1

I'm considering using TypeScript instead of JavaScript for a very big project. The question is: what are the benefits I can gain. TypeScript provides interfaces, strict typing and so on. But the thing that is the most important is whether TypeScript is compiled. By compilation I mean a real compilation just like Java has. I don't need JavaScript's minification (uglification, etc. - some people call it compiling). I don't mean Python's compilation as well.

So the question is: will TypeScript throw an error at compile-time if a developer makes a mistake before runtime, just as Java would?

2 Answers 2

4

Yes.

The whole point of Typescript is compile-time type checking.

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

Comments

1

Typescript introduces a compile-time type checking system, which can warn you about errors before runtime.

TS does not compile into a binary representation like Java, it simply transpiles into Javascript which is later interpreted (or compiled) and run by the browser.

What Typescript does offer, of particular value for large codebases, is essentially a layer of static analysis prior to runtime. In TS' case, that's centered around publishing type expectations and the contracts those types provide, then verifying they are met from all visible code.

2 Comments

Eventually, I wanna write a single-page app (based on angular, if that makes any difference). The code would be transpiled into javascript and executed as so in the browser. So may I assume that any compile-time errors would be thrown on transpilation (called by npmjs.com/package/grunt-typescript)?
Yes, TSC (the compiler) prints any type errors it encounters as it transpiles the files in JS. You can (and at work I do) use this to fail the build, just as if it were a compile error in some other language.

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.