I read that typescript introduces the concept of assigning the variable "a type" so that we can avoid type errors at runtime.
I tried implementing the "type" concept in VS_CODE.
This is the code i tried
//main.ts
let message = "Hello all of you!!"
console.log(message);
let message2 : string = "Welcome typescript with the concept of
'type' ";
console.log(message2);
message2 = 233;
console.log(message2);
This is the error i got in the console.
main.ts:9:1 - error TS2322: Type '233' is not assignable to type
'string'.
9 message2 = 233;
[00:30:56] Found 1 error. Watching for file changes.
Transpiled JS Code
//main.js
"use strict";
var message = "Hello all of you!!";
console.log(message);
var message2 = "Welcome typescript with the concept of 'type' ";
console.log(message2);
message2 = 233;
console.log(message2);
JS Output
venkat-6805:Typescript-basics venkat-6805$ node main
Hello all of you!!
Welcome typescript with the concept of 'type'
venkat-6805:Typescript-basics venkat-6805$ node main
Hello all of you!!
Welcome typescript with the concept of 'type'
233
venkat-6805:Typescript-basics venkat-6805$ ;
So my question is
Won't typescript stop transpilation when it finds an error?
Eventually, every typescript code is converted into JS code. Then what is the use of typescript?