1

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

3 Answers 3

2

You can set the noEmitOnError setting in your tsconfig.json to true (defaults to false).

Sign up to request clarification or add additional context in comments.

4 Comments

but this parameter just prevent updating of my .js file. And my old js file still work. But I need to compiler crash app at all (to noitfiy me about error and force fix error immediately).
Instead of running tsc (or however you compile your code), you could add in a Node script that deletes the file in question (such as deleting the entire contents of the output directory), then runs tsc. If you're using Webpack, here's an option.
hmm, sounds good. But I can't set up webpack yet. May be there are simplier way?
You don't need Webpack, that's just an example. Just write the Node script, then change your build process from running TS to running the Node script, which runs TS.
0

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.