0

We create a TS file in vscode and report an error to us after deliberately writing a wrong type. Is the type checked at this time? We haven't done anything yet.

So when did typescript start type checking?

Dasheng
  • 67
  • 6
  • 1
    Most IDEs will typecheck as you write code - is that what you're asking? – mbdavis Mar 25 '22 at 11:30
  • Modern IDEs have blurred the line between "compile time" and "I'm just editing code in the editor" by either doing full builds in the background or by introducing an additional "analyzing" layer that does basically the same thing as full compilation, but usually in a faster way that supports fast redos when stuff changes. So yes, TS is type-checked at build time, but your IDE may provide *some* (or all) of those checks even when you don't explicitly push "build". – Joachim Sauer Mar 25 '22 at 11:36
  • At least related: [*What is TypeScript and why would I use it in place of JavaScript?*](https://stackoverflow.com/questions/12694530/what-is-typescript-and-why-would-i-use-it-in-place-of-javascript) – T.J. Crowder Mar 25 '22 at 11:38

1 Answers1

2

Is TypeScript also type checked at compile time?

Yes. In fact, other than a very small aspect related to enums, TypeScript doesn't exist at runtime at all. TypeScript compiles to JavaScript, which is a dynamically-typed language.

We haven't done anything yet. ... So when did typescript start type checking?

VSCode, like many IDEs, will run TypeScript under the covers as you're working to type-check the code and report issues, which the IDE then reports to you. The IDEs run TypeScript in "no emit" mode (it doesn't produce its usual JavaScript output) so it's just doing syntax checking (because it has to to do its job) and type checking (its primary job).

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • Thank you. So when we finish writing the code, vscode will compile automatically, but no JS file will be generated – Dasheng Mar 25 '22 at 11:48
  • @Dasheng - *As* you're writing, yes, if you pause even for a moment. Then later, of course, when you want to build your project to deploy it, you'll use TypeScript (or a TypeScript-compatible compiler) to produce the JavaScript to run. – T.J. Crowder Mar 25 '22 at 12:03