Why use type checking?

Along with the tremendous flexibility of JavaScript comes great risk: silent runtime errors, unclear function contracts, and endless debugging sessions. While it is certainly possible to produce reliable JavaScript programs with good programming practices and attention to detail, most JavaScript projects grow into a state of chaos.

TypeScript was created for the purpose of producing reliable JavaScript programs with far less effort. It does place a certain amount of burden on the programmer to start defining types, but in return it provides a wide range of error-prevention features that tightly integrate with a better developer experience.

Date can return a string or an object

Calling Date() in JavaScript returns a string, while calling new Date() returns an object. This is a subtle error that can be hard to detect, especially since both values will display the correct timestamp when passed to console.log.

Loading TypeScript...

TypeScript captures the idiosyncrasies of JavaScript, and will automatically detect most types.

Was this page helpful?