Search code examples
javascriptnode.jsangulartypescriptmaterialize

How to ignore "Cannot find name 'M' " error in typescript?


I'm integrating a pure javascript library(materialize.js) with my angular typescript app. While activating the sidenav, I need to use the code.

M.Sidenav.init(document.querySelector('.sidenav'), [])

This works, and the sidenav is initiated, however, since I didn't define any M anywhere in the typescript file, the angular compiler raises an error

ERROR in src/app/app.component.ts(34,5): error TS2304: Cannot find name 'M'.

Is there any way I can make typescript ignore this error, or in any way, fix it?


Solution

  • You can follow these steps

    npm install --save materialize-css 
    
    npm install --save @types/materialize-css
    
    declare const M;
    
    import { SideNav } from "materialize-css";