admin管理员组文章数量:1297123
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 piler raises an error
ERROR in src/app/appponent.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?
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 piler raises an error
ERROR in src/app/app.ponent.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?
Share Improve this question asked Nov 4, 2018 at 3:29 Dustbin Saves youDustbin Saves you 1261 silver badge8 bronze badges 3- what is M suppose to be? if M is materialize.js, you will need to import it using require()/import – Mox Commented Nov 4, 2018 at 3:31
- use 'declare const M'; Also make sure library script file is included and imported. – Suresh Kumar Ariya Commented Nov 4, 2018 at 4:23
- Thanks! I using 'declare const M' solved the problem – Dustbin Saves you Commented Nov 8, 2018 at 8:20
1 Answer
Reset to default 9You can follow these steps
npm install --save materialize-css
npm install --save @types/materialize-css
declare const M;
import { SideNav } from "materialize-css";
本文标签: javascriptHow to ignore quotCannot find name 39M39 quot error in typescriptStack Overflow
版权声明:本文标题:javascript - How to ignore "Cannot find name 'M' " error in typescript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741609590a2388181.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论