> front-end

Basic Types

Created by: Kitman Yiu

Updated at: 1 day ago

  • Definition: is a superset of JavaScript, adding a type system and compile-timetype checking.
  • Benefits: Allowed developers to detect potential type errors during coding
  • Keywords: Superset of JS, Detect potential type errors during coding

1. Where does it come from?

TypeScript was born to provide a type system and support for ES6+ on top of JavaScript. Before TypeScript's emergence, JavaScript, as a dynamically typed language, was highly flexible but prone to type errors in large projects. TypeScript’s introduction allowed developers to detect potential type errors during coding.

2. What is it?

TypeScript is a superset of JavaScript, adding a type system and compile-time type checking. The three key principles of TypeScript include:

  • Type Annotation: Allowing developers to specify the type of variables.
  • Interfaces: Defining the structure of objects.
  • Classes and Modules: Supporting the latest ES6+ features.

A simple example: In JavaScript, you might accidentally add a string to a number. Using TypeScript, you can specify types for variables, like let num: number = 5; and let str: string = "hello";. This way, when you try num + str, TypeScript will prompt an error at compile time.

3. Where is it going?

The main limitation of TypeScript is that it adds to the learning curve and development time. Currently, the industry is optimizing towards improving compiler performance and enhancing support for modern JavaScript features. In the future, TypeScript may continue to deepen its integration with the JavaScript ecosystem, providing more intelligent type inference and more efficient compilation strategies.