【发布时间】:2020-07-04 09:37:45
【问题描述】:
我的团队正在处理我们最近升级到 .Net Core 3.1 的较旧的 AngularJS 项目,而没有它,该项目工作正常,我们想开始升级我们的脚本以使用 TypeScript。我们之前没有人真正使用过 Typescript,我敢肯定我们的配置中有一些非常基本的东西。
我已经建立了一个演示项目,可以在这里找到: https://github.com/ExcaliburVT/TypeScriptBasic
该项目有 angularjs、angular material、bootstrap 等的 libman 引用以及它们相应的 TypeScript“类型”(至少我认为它们是正确的)。 这里:https://github.com/ExcaliburVT/TypeScriptBasic/blob/master/libman.json
我们的 tsconfig.json 就是这样的: https://github.com/ExcaliburVT/TypeScriptBasic/blob/master/tsconfig.json
{
"compilerOptions": {
"noImplicitAny": true,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es6",
"moduleResolution": "Node",
"baseUrl": "wwwroot",
"typeRoots": ["./lib/types"]
},
"include": [
"wwwroot/Scripts/**/*"
],
"exclude": [ "node_modules", "**/*.spec.ts" ],
"compileOnSave": true
}
最后,我创建了两个示例 ts 文件,它们使用不同的方式尝试引用 angular。
https://github.com/ExcaliburVT/TypeScriptBasic/blob/master/wwwroot/Scripts/exampleOne.ts //TS2304(TS) 找不到名称 'angular' //TS2503(TS) 找不到命名空间'ng'
https://github.com/ExcaliburVT/TypeScriptBasic/blob/master/wwwroot/Scripts/exampleTwo.ts //TS2688(TS) 找不到 'angular' 的类型定义文件
如果我们在 tsconfig.json 的“include”中添加类型文件夹的路径,那么就会发现库似乎找到了,但是我们会得到类型本身的编译器错误。
我确定我们的设置错误很简单,但我没有想法。
提前致谢!
附加测试。请注意,直接设置路径似乎也不起作用。
"baseUrl": "wwwroot",
"paths": {
"angular": [ "lib/types/angular" ],
"angular-material": [ "lib/types/angular-material" ],
"bootstrap": [ "lib/types/bootstrap" ],
"jquery": [ "lib/types/jquery" ]
}
【问题讨论】:
标签: asp.net .net angularjs typescript .net-core