js to ts nextjs
Answered
Silver Fox posted this in #help-forum
Silver FoxOP
how do i convert my app to ts
Answered by B33fb0n3
at the end typescript is just typed javascript.
So instead of having a plain variables like:
You can "type" this javascript variables:
Now as you can see, typescript expect the variable to be a string. Make sure to change your file as well (you either want to have
And if you are using stuff like tailwind, make sure to change it inside your config as well
So instead of having a plain variables like:
const variables = 'hello world'You can "type" this javascript variables:
const variables: string = 'hello world'Now as you can see, typescript expect the variable to be a string. Make sure to change your file as well (you either want to have
.ts or .tsx)And if you are using stuff like tailwind, make sure to change it inside your config as well
8 Replies
If you created the app via
“create-next-app” it comes with TypeScript preconfigured, you can check this by finding a tsconfig.json in the root directory of your project
“create-next-app” it comes with TypeScript preconfigured, you can check this by finding a tsconfig.json in the root directory of your project
And checking of you have the TypeScript package installed in package.json under “devDependencies”
In case you already have TypeScript set up but you don’t use it, it’s just matter of switching the file extensions from “.js” and “. jsx” to “.ts” and “.tsx”
In case you already have TypeScript set up but you don’t use it, it’s just matter of switching the file extensions from “.js” and “. jsx” to “.ts” and “.tsx”
@Silver Fox how do i convert my app to ts
at the end typescript is just typed javascript.
So instead of having a plain variables like:
You can "type" this javascript variables:
Now as you can see, typescript expect the variable to be a string. Make sure to change your file as well (you either want to have
And if you are using stuff like tailwind, make sure to change it inside your config as well
So instead of having a plain variables like:
const variables = 'hello world'You can "type" this javascript variables:
const variables: string = 'hello world'Now as you can see, typescript expect the variable to be a string. Make sure to change your file as well (you either want to have
.ts or .tsx)And if you are using stuff like tailwind, make sure to change it inside your config as well
Answer
@Silver Fox solved?
Silver FoxOP
yes