我试图为Faby安装类型定义(https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/fabric/),但我无法找到正确的类型命令。
起初,我尝试typings install dt~fabric --global --save
并得到以下错误:$typings install dt~fabric --global --savetypings ERR! message Attempted to compile "fabric" as a global module, but it looks like an external module. You'll need to remove the global option to continue.
然后我尝试了typings install dt~fabric --save
,类型命令成功了,但是typings/modules/fabric/index.d.ts
文件与原始文件https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/fabric/index.d.ts
不同。typings
命令将原始内容封装为declare module 'fabric' {}
,这会导致编译器错误Error:(9, 1) TS1316:Global module exports may only appear at top level.
在.d.ts文件内的语句export as namespace fabric;
中。
打字版本2.1.0
最佳答案
npm install --save @types/fabric
会成功的,per the NPM docs.
您可以看到type definitions here.
我在学习织物时使用了这一点,这对于理解API来说是一个巨大的帮助,这是因为智能感知。
此外,如果在任何*.js文件的顶部使用
//@ts-check
,它也会粗略地估计它认为正确的智能感知。TypeScript2.3及更高版本支持使用--checkjs检查.js文件中的类型并报告错误的模式。The docs explain how it works.
关于typescript - 如何为Fabric安装.d.ts,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42547692/