I have simple asp.net core web application, where I have installed javascript libraries using libman.
I want to use typescript, so I have installed typescript definition files for the libraries using npm, e.g:
npm install @types/jquery --save-dev
npm install @types/bootstrap --save-dev
I would like to add the .d.ts files to source control, so that other developers does not have to rely on NPM - it is the purpose of libman, isn't it?
/node_modules folder is ignored in .gitignore by default.
How do I include the typescript definition files?
Since you have installed javascript libraries using LibMan
, you could simply reuse the LibMan
to install the definitions too :
libman install @types/jquery -p unpkg
libman install @types/bootstrap -p unpkg
The default path will be libs/@types
:
lib/
@types/
bootstrap/
index.d.ts
...
jquery/
index.d.ts
...
I create a tsconfig.json
and configure path mapping to load modules as below :
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"jquery": ["lib/@types/jquery"] ,
"bootstrap":["lib/@types/bootstrap"]
}
}
}
Now we can benefit from the typescript:
[Update]
For ASPNET-CORE project, the default path will be :wwwroot/lib/@types
, if we have our tsconfig.json
under the project directory (next to the *.csproj
project file ), we need change the path to :
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"jquery": ["wwwroot/lib/@types/jquery"] ,
"bootstrap":["wwwroot/lib/@types/bootstrap"]
}
}
}