_ 误导,js 不存在 private
TypeScript Types
Any, Void, Never
Interface, Tuple, Enum
# TypeScript Types
https://www.typescriptlang.org/docs/handbook/basic-types.html
https://www.typescriptlang.org/docs/handbook/advanced-types.html
```ts
Boolean
Number
String
Array
Tuple
Enum
Any
Void
Null and Undefined
Never
Object
// Type assertions
// A note about ‘let’
```
```ts
Intersection Types
Union Types
Type Guards and Differentiating Types
User-Defined Type Guards
Using type predicates
Using the in operator
typeof type guards
instanceof type guards
Nullable types
Optional parameters and properties
Type guards and type assertions
Type Aliases
Interfaces vs. Type Aliases
String Literal Types
Numeric Literal Types
Enum Member Types
Discriminated Unions
Exhaustiveness checking
Polymorphic this types
Index types
Index types and index signatures
Mapped types
Inference from mapped types
Conditional Types
Distributive conditional types
Type inference in conditional types
Predefined conditional types
```
https://www.typescriptlang.org/docs/handbook/utility-types.html
```ts
Partial<T>
Readonly<T>
Record<K,T>
Pick<T,K>
Omit<T,K>
Exclude<T,U>
Extract<T,U>
NonNullable<T>
Parameters<T>
ConstructorParameters<T>
ReturnType<T>
InstanceType<T>
Required<T>
ThisParameterType
OmitThisParameter
ThisType<T>
```
TS的特点:
TS 常见类型
Boolean Number String Array
Tuple Enum interface class
Any Void Null Undefined Never(某个函数不可返回)
变量声明
const/var/let 变量: 类型
函数声明
function 函数名(参数1: 类型1, 参数2: 类型2): 返回类型 {}
箭头函数
(参数1: 类型1, 参数2: 类型2):返回类型 => {}
类成员的声明
class 类名 {
// 私有变量
private _x: number;
private _y: number;
...
}
未声明类型默认作为 any 类型
声明类成员类型、方法/函数的参数类型和返回类型
能明确推导时 局部变量/箭头函数 可以不申明类型
ts小结:
申明类型-函数
申明类型-变量/常量
const 常量名:类型
let 变量名:类型
var 变量名:类型
TypeScript的常见类型
TypeScript在JavaScript里面独有的语法
typescript的常见类型
mac下删除文件命令
rm *.js -s rm **/*.js -s