You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
letmyFavoriteNumber: string|number;myFavoriteNumber='seven';myFavoriteNumber=7;// number类型没有length属性,所以会报错functiongetLength(something: string|number): number{// Property 'length' does not exist on type 'number'.returnsomething.length;}
Uh oh!
There was an error while loading. Please reload this page.
基础
1. 原始类型(boolean,number,string,undefined,null)
2. void空类型,可表示无返回值的函数
3. 任意值类型,可重新赋值
变量如果在声明的时候,未指定其类型,那么它会被识别为任意值类型:
4. 类型推论 如果没有明确的指定类型,那么 TypeScript 会依照类型推论(Type Inference)的规则推断出一个类型
5. 联合类型
当 TypeScript 不确定一个联合类型的变量到底是哪个类型的时候,我们只能访问此联合类型的所有类型里共有的属性或方法:
6. 对象的类型——接口 Interfaces
7. 数组类型
8. 函数类型
9. 类型断言
10. 声明文件
11. 内置对象
The text was updated successfully, but these errors were encountered: