TypeScript's type system has a minor impact on how variables are referenced and declared, yet it has a huge impact on maintainability and consistency.
let foo = 1
let bar = "text"
Here are the same variables declared and initialized in TypeScript:
let foo: number = 1
let bar: string = "text"
bar = 123 // not allowed in TypeScript
The difference in syntax is minor.
However, the use of number and string types allows TypeScript to enforce the rule that: If a variable is declared as a given type, it is not allowed to arbitrarily change its type later on in the program.
The introduction of a type system doesn't seem like a big deal, but it has a major impact on how to manage large applications.
- Computers with single-core processors.
- CPU speeds measured in double-digit megahertz, not gigahertz.
- Devices with less than 1 MB of RAM.
- Typical download speeds of 14.4-56 Kbps.
- No access to network ports or the file system.
- Execution entirely within the confines of a webpage.
TypeScript was designed from the ground up to be an elegant, fully object-oriented programming language that provides functional features and optional design-time type-checking.
Optional strong typing
Community and adoption
Larger than TypeScript
.js and .jsx
.ts and .tsx
Limited validation and refactoring capabilities
Extensive validation and refactoring capabilities
Easy scripting language for new developers to learn
Additional features require an investment of time to learn
Large code bases are harder to read and decipher
Type system and object-oriented approach improve readability
ECMAScript vs. TypeScript
- TypeScript IDEs have more features, as it is easier to build plugins and tools for a statically typed language.
- TypeScript code is easier to debug as the codebase expands, because type errors can be discovered at compilation time rather than runtime.