NextJS not showing TypeScript errors on Runtime #13617
-
Hey I have a NextJS 9.4 project with the default TypeScript config files When developing in the IDE it shows the errors but running the browser, it continues normally, I would like to provide an error in the browser. For example, CRA has this behavior. The code example below in the IDE shows an error but the code stills compile and works in the browser. 😓 const mathTest = (number1: number, number2: number) => {
return number1 + number2;
};
console.log("number = ", mathTest(2, "22")) My tsconfig.json {
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext", "esnext.intl"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"allowSyntheticDefaultImports": true,
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"exclude": ["node_modules"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
} If I run the tsc in the terminal it shows the correct errors and warnings, I need the project to be strict and not let developers continue working in the project with this kind of errors. Can someone help me understand this Nextjs behavior? The validation works correctly on build but can I have the same experience on dev |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I am not sure if there is a way to enable runtime type errors, but in my experience it is better if your environment doesn't crash with type errors. Sometimes you want to test something and don't care for the types, but if you app keeps giving an error you have to waste a lot of time fixing the types for something you won't even use anyway. In my TS projects, I create a npm script called
If you want to make sure you aren't merging code with type errors, you can include this command in your CI tasks too, before the build. |
Beta Was this translation helpful? Give feedback.
-
I am in the middle of setting things up to migrate to Next.js, and will report back, but currently we have https://www.npmjs.com/package/fork-ts-checker-webpack-plugin setup, and it by default is async and will not cause a build error for type errors. this would report in the console while developing as an extra piece of feedback. |
Beta Was this translation helpful? Give feedback.
I am not sure if there is a way to enable runtime type errors, but in my experience it is better if your environment doesn't crash with type errors. Sometimes you want to test something and don't care for the types, but if you app keeps giving an error you have to waste a lot of time fixing the types for something you won't even use anyway.
In my TS projects, I create a npm script called
type-check
that I can run whenever I change something and want to make sure all the codebase is still correct:If you want to make sure you aren't merging code with type errors, you can include this command in your CI tasks too, before the build.