I am trying to load fonts dynamically for my project. I dont understand why I'm getting this error.
"Cannot find name 'FontFace'. TS2304"
Following is the code for your reference:
const loadFont = (name: string, source: string) => {
const font = new FontFace(name, `url(${source})`);
font
.load()
.then(function (loadedFont: any) {
document.fonts.add(loadedFont);
document.body.style.fontFamily = name;
})
.catch(function (error) {
console.log(error);
});
};
If you are using Typescript, make sure you have installed type definitions for CSS Font loading modules
npm install --save @types/css-font-loading-module
Ref: https://www.npmjs.com/package/@types/css-font-loading-module