I am writing an ASP.NET Core 5 app and instead of using JS I want to use TypeScript.
I'm using some JS libraries, so in order for the TS to compile it needs definitions for them.
I've set up NPM with devDependencies of the type definitions for the libraries, which downloads them to node_modules, and the TS compiler finds and uses them.
My NPM package.json
is:
{
"version": "1.0.0",
"name": "asp.net",
"private": true,
"devDependencies": {
"@types/bootstrap": "5.0.17",
"@types/jquery": "3.5.6",
"bootstrap-table": "^1.18.3",
"jquery": "3.6.0"
}
}
My tsconfig.json
is:
{
"compilerOptions": {
"noImplicitAny": true,
"noEmitOnError": true,
"removeComments": true,
"sourceMap": true,
"target": "es5",
"lib": [
"DOM",
"ES5",
"ES2015"
]
},
"include": [
"wwwroot/js/**/*.ts"
],
"exclude": [
"node_modules"
],
"compileOnSave": true
}
This works for JQuery and Bootstrap, but it's not working for bootstrap-table.
My project structure is:
root
wwwroot
js
home.ts
views
home
index.cshtml // imports ~/js/home.js
node_modules // the folders in here are automatically maintained by NPM
@types
bootstrap
jquery
bootstrap-table
package.json
tsconfig.json
The error when compiling home.ts
is (TS) Property 'bootstrapTable' does not exist on type 'JQuery<HTMLElement>'.
I thought the problem might be caused by the type definitions for bootstrap-table being included in the main library, which means it's not in the @types subdirectory of node_modules.
I've tried forcing the TS compiler to see it by manually specifying typeRoots but there are just a lot of compile errors because it starts seeing all sub-folders as modules that are missing.