TypeScript provides compile time (not runtime) types safety for JavaScript code
Ts is intentionally and strictly a superset of JavaScript with optional type checks which means you can rename your .js file to a .ts file and typescript will still give you back a valid .js file equivalent to the original JavaScript file.
typescript will try to infer as much of the types as it can.
var foo = 123;
foo = '456'; // Error: cannot assign `string` to `number`
// Is foo a number or a string?
TypeScript knows that the type of the variable “foo” is number with your given value.
You can use annotation to refer to a specific type. We often do that for two reasons:
TypeScript uses postfix type annotation.
const foo: number = 123;
Ts provides type safety for JavaScript developers with a minimum cognitive overload.
Duck Typing is a first class language construct.