We are currently working on revitalizing an older AngularJS project by migrating it to .Net Core 3.1. As part of this process, we are looking to transition our scripts to TypeScript. While the project is functioning properly without TypeScript, we believe there may be some basic configuration errors causing issues.
To troubleshoot, I have created a demo project that can be accessed here: https://github.com/ExcaliburVT/TypeScriptBasic
The project includes libman references for AngularJS, Angular Material, Bootstrap, and more, along with their corresponding TypeScript "typings" (which we assume are correct). You can view the libman.json file here: https://github.com/ExcaliburVT/TypeScriptBasic/blob/master/libman.json
Our tsconfig.json file is set up as follows: 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
}
Furthermore, I have created two example TypeScript files that demonstrate different approaches to referencing Angular.
https://github.com/ExcaliburVT/TypeScriptBasic/blob/master/wwwroot/Scripts/exampleOne.ts //TS2304(TS) Cannot find name 'angular' //TS2503(TS) Cannot find namespace 'ng'
https://github.com/ExcaliburVT/TypeScriptBasic/blob/master/wwwroot/Scripts/exampleTwo.ts //TS2688(TS) Cannot find type definition file for 'angular'
When we attempted to include the paths to the types folders in the "include" section of tsconfig.json, the libraries seemed to be recognized, but we encountered compiler errors related to the types themselves.
We believe that the issue is a simple configuration error that we have overlooked. Any guidance on how to resolve this would be greatly appreciated.
Thank you in advance!
Additional testing revealed that directly setting the paths did not yield successful results either.
"baseUrl": "wwwroot",
"paths": {
"angular": [ "lib/types/angular" ],
"angular-material": [ "lib/types/angular-material" ],
"bootstrap": [ "lib/types/bootstrap" ],
"jquery": [ "lib/types/jquery" ]
}