Reputation: 109
I'm learning typescript and there are problem that when I'm having error in my typescript code, my javascript code is still running (notwithstanding of error).
I want to my .js
file
dont creates at all
or creates and be empty
or creates valid .js
code, which throw error into console
if there is error in my .ts
file.
* It would be great to make it using .tsconfig
, not command line.
* I know about noEmitOnError, but it just prevent updating of my js file. But dont crush it. And I need to crashing of js when ts has error
Upvotes: 1
Views: 1679
Reputation: 1
step 1: First write the command "tsc --init" in your terminal then you will get tsconfig.js file
step 2: Just set "noEmitOnError": true, in your tsconfig.js file
Upvotes: 0
Reputation: 1
In TypeScript, you can define the types of variables to ensure type safety and catch errors at compile time. This means that if you declare a variable as a specific type, TypeScript will expect that variable to only hold values of that type.
In your case, you declared a variable as type number, but assigned it a string value. TypeScript should have caught this error at compile time and thrown a type error, indicating that you cannot assign a string to a variable of type number.
However, you're saying that TypeScript allowed the code to compile to JavaScript without any errors. This could happen if you're using the --noEmitOnError flag when compiling your TypeScript code, which will prevent TypeScript from emitting any JavaScript output if there are any type errors. If you're not using this flag, it's possible that there was some other issue in your configuration that caused TypeScript to skip the type checking step.
In any case, it's important to always ensure that your code is correctly typed and to use TypeScript's type checking features to catch errors early in the development process.
Upvotes: 0
Reputation: 370729
You can set the noEmitOnError
setting in your tsconfig.json to true
(defaults to false
).
Upvotes: 2