Skip to content
Discussion options

You must be logged in to vote

Converting a .NET 8 React Project from JavaScript to TypeScript

If you want to switch your React frontend to TypeScript, follow these simple steps:

  1. Install TypeScript and type definitions
npm install --save typescript @types/node @types/react @types/react-dom @types/jest

Rename Your Files

  • .js.ts (for normal files)
  • .jsx.tsx (for files with JSX)

Add a tsconfig.json

{
  "compilerOptions": {
    "target": "ES6",
    "module": "ESNext",
    "jsx": "react-jsx",
    "strict": true
  },
  "include": ["src"]
}

Fix Types and Imports

  • Install missing types for libraries you use, e.g.:
npm install --save-dev @types/react-router-dom

Tip: For a fresh setup, you can also run:

dotnet new…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Nhatan1205
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants