Skip to content

How to add typescript to an existing vite react app? #6799

Answered by anasouardini
arunabhg asked this question in Q&A
Discussion options

You must be logged in to vote

!. install typescript, @types/react and @types/react-dom.
2. in packages.json, replace vite build with tsc && vite build.
3. configure your TS:

tsconfig.json

{
  "compilerOptions": {
    "target": "ESNext",
    "useDefineForClassFields": true,
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "allowJs": false,
    "skipLibCheck": true,
    "esModuleInterop": false,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "ESNext",
    "moduleResolution": "Node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": ["src"],
  "references": [{ "path": "./tscon…

Replies: 8 comments 19 replies

Comment options

You must be logged in to vote
1 reply
@arunabhg
Comment options

Comment options

You must be logged in to vote
1 reply
@arunabhg
Comment options

Comment options

You must be logged in to vote
8 replies
@arunabhg
Comment options

@julianmagra
Comment options

@julianmagra
Comment options

@arunabhg
Comment options

@julianmagra
Comment options

Answer selected by arunabhg
Comment options

You must be logged in to vote
3 replies
@gatinhap
Comment options

@strudelPie
Comment options

@BenGardiner123
Comment options

Comment options

You must be logged in to vote
2 replies
@murtuzaalisurti
Comment options

@slav-getov
Comment options

Comment options

You must be logged in to vote
3 replies
@DevPowers
Comment options

@JuanQP
Comment options

@DevPowers
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jfvillablanca
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet