I created an asp.net core Reactjs project via Visual Studio 2022. Unfortunately everything is in javascript (not typescript).
How can i enable typescript for this project?
CodePudding user response:
You can compile TypeScript code with NuGet.
First, Add TypeScript support with NuGet : Microsoft.TypeScript.MSBuild
.
Then, Add the tsconfig.json
file to the project root. You can use this file to configure options for the TypeScript compiler.Like this:
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5",
"outDir": "wwwroot/js"
},
"include": [
"scripts/**/*"
]
}
Lastly, Add TypeScript (.ts) or TypeScript JSX (.tsx) files to your project, and then add TypeScript code.
For more details, you can refer to this document and this link.
Hope this can help you.