[转]TypeScript 引入js库
TypeScript 引入js库
如果要使用现有的js文件的话,需要对编译器增加–allowJS参数。可以修改tsconfig.json中的compilerOptions,将其中的"allowJs"设为true,如: “allowJs”: true,没有该字段的话增加该字段即可。另外在tsconfig中的"include"字段中将js文件的路径添加进去。建议增加一个专门的文件夹,用来存放所有要引入的js文件。比如都放到一个名为"jslibs"的目录中,然后在tsconfig.json的"include"字段中增加配置,匹配"jslibs"下的所有js文件,如:
{ "compilerOptions": { "strictNullChecks": true, "noImplicitAny": true, "module": "CommonJS", "target": "ES5", "allowJs": true, "experimentalDecorators": true, "noImplicitThis": true, "noImplicitReturns": true, "alwaysStrict": true, "inlineSourceMap": true, "inlineSources": true, "noFallthroughCasesInSwitch": true, "noUnusedLocals": true, "noUnusedParameters": true, "strict": true, "removeComments": true, "pretty": true, "strictPropertyInitialization": true, "typeRoots": [ "typings" ] }, "include": [ "./**/*.ts", "./src/jslibs/*.js" ], "exclude": [ "node_modules", "miniprogram_dist", "**/*.spec.ts" ] }
原文链接:https://blog.csdn.net/candyguy242/article/details/84619884
相关推荐
88274956 2020-11-03
Zhongmeishijue 2020-09-10
runner 2020-09-01
梦的天空 2020-08-25
IdeaElements 2020-08-19
luvhl 2020-08-17
移动开发与培训 2020-08-16
ReunionIsland 2020-08-16
lyqdanang 2020-08-16
NARUTOLUOLUO 2020-08-03
MyNameIsXiaoLai 2020-07-08
星辰的笔记 2020-07-04
csstpeixun 2020-06-28
letheashura 2020-06-26
liaoxuewu 2020-06-26
OldBowl 2020-06-26
北京老苏 2020-06-25
Luffyying 2020-06-25