function
Function Arguments
- Parameter and return type
function add(x: number, y: number): number {
return x + y
}
function add(x: number, y?: number): number {
return x + 10
}
function add(x: number, y: number = 20): number {
return x + y
}
function sum(...args: number[]): number {
let ret: number = 0
args.forEach((item: number): void => {
ret += item
})
return ret
}
sum(1, 2, 3)
Arrow function
let add = (x: number, y: number): number => x + y
for-of loop
- for loop
- forEach
- It does not support the break
- for in
- As will an array of objects to traverse
- for of
Type inference (Type Inference)
Type compatibility
Module
concept
Communication module: Export
export default xxx
export const foo: string = 'bar';
export const bar: string = 'foo';
Communicating: Import
// 加载默认成员
import xxx from '模块标识'
// 按需加载模块成员
import {foo, bar} from '模块'
TypeScript summary
- What is TypeScript
- Variable declaration
- Basic data types
- Boolean value
boolean
- digital
number
- String
string
- Array
number[]
orArray<number>
- Originator
[number, string]
- Object
object
, you can understand
- Any type
any
- Function returns an empty value
void
null
with undefined
- interface
- Deconstruction assignment
- An array of deconstruction
- Object deconstruction
- Operators Expand
- Expand Arrays
- Expand the object
- class
- The basic syntax
- Constructor
- inherit
- Property modifiers
- get and set properties
- function
- for-of loop
- Module