Home > OS >  Property 'zoom' does not exist on type 'CSSStyleDeclaration'
Property 'zoom' does not exist on type 'CSSStyleDeclaration'

Time:10-13

Below is my code : app.component.ts

export class AppComponent implements OnInit {

  ngOnInit(): void {
    //throw new Error('Method not implemented.');
    let a = (document.getElementsByTagName('html') as HTMLCollectionOf<HTMLHtmlElement>)[0];
    if(window.innerWidth  > 769 ){
      var percentageOn1 = window.innerWidth / 1920;
      a.style.zoom="" (percentageOn1*100) "%"; // Error : Property 'zoom' does not exist on type 'CSSStyleDeclaration'
    }
    else{
      a.style.zoom="100%" // Error : Property 'zoom' does not exist on type 'CSSStyleDeclaration'
    }
  }

}

BTW the project still works but I still have this error.

CodePudding user response:

Open lib.dom.d.ts path like this ( C:\Program Files\Microsoft VS Code\resources\app\extensions\node_modules\typescript\lib\lib.dom.d.ts ) search: "interface CSSStyleDeclaration" and add this line : zoom: string;

like this :

interface CSSStyleDeclaration {
    alignContent: string;
    alignItems: string;
    alignSelf: string;
    //....
    //....;
    zoom: string; // add this
    //....
    //....;
}
  • Related