Do simple things over and over again and make a little progress every day

Document your own TypeScript learning process.

TypeScript source

TypeScript originated in large projects developed using JavaScript. Due to the limitations of JavaScript language itself, it is difficult to be competent and maintain large project development. So Microsoft developed TypeScript to make it suitable for large projects.

Summary of TypeScript

  • A language built on javascript with full support for javascript
  • A superset of javascript
  • It can be executed on any platform that supports javascript, and TypeScript can compile to any version of javascript
  • TypeScript: Extends javascript to introduce the concept of types

Development environment setup

1. Install node (skip this step if node is available)

2, install typescript (NPM install -g typescript)

Test the typescript

1, create hello. Ts file on drive D (any directory will do)

CMD to the new hello.ts directory

TSC hello.ts generates a hello.js file in the current directory, proving that the TypeScript development environment is set up successfully.

1. Data types

Boolean: let isDone: Boolean = false; Let decLiteral: number = 6; String: let name: string = "Bob "; Let list: number[] = [1, 2, 3]; Let list: Array<number> = [1, 2, 3]; Tuple: let x: [string, number]; x = ['hello', 10]; // OK x = [10, 'hello']; // Error enumeration: enum Color {Red = 1, Green, Blue} let c: Color = color.green; Any: Void: let unusable: Void = undefined; Null and undefined: let u: undefined = undefined; let n: null = null; Object: let obj: {name: string, age: number} = {name: 'zhangsan', age: 18}Copy the code

2. Type declaration

Function fn(a: number, b: number): function fn(a: number, b: number): Number {return a-b} fn(1, 2) // The parameter and return value of the declared function are of the number type, and the number of parameters to be passed must be twoCopy the code