根据this的文章,TypeScript2.0的类型系统已经发生了变化,因此现在还不清楚如何附加自定义类型。我应该总是为它创建NPM包吗?
提前谢谢你!
发布于 2017-01-18 05:19:53
您可以只为您的项目创建本地自定义类型,其中您可以为JS库声明类型。为此,您需要:
。 index.d.ts tsconfig.json中的├──custom_typings│和└──│└──└──
index.d.ts文件中,为JS库添加一个声明:声明模块'some-js-lib‘{导出函数hello(world: string):}
tsconfig.json的compilerOptions部分中添加对此类型声明的引用:{ "compilerOptions":{ ..."typeRoots":"./node_modules/@types","./custom_typings“},... }
从'some-js-lib‘hello('world!')导入{ hello }
https://stackoverflow.com/questions/38971984
复制相似问题