基础数据类型
| |
|---|
| /字符串/ | const q = 'string'; | const q : 'string'; |
| /布尔值/ | const w = true; | const w : true; |
| /数字/ | const e = 1; | const e : 1; |
| /null/ | const r = null; | const r : null; |
| /undefined/ | const t=nudefined; | const t : nudefined; |
对象类型
const bytedacer: IBytedabcer = {
jobId:163764,
name:'Li',
sex:'man',
age:12,
hobby:'reading',
}
interface IBytedancer{
readonly jobId: number;
name: string;
sex: 'man' | 'woman' | 'other' |;
age: number;
hobby?:string;
[key: string]: any;
}
bytedancer.jobId = 12344;
const bytedancer2: bytedancer = {
jobId: 2563,
sex: 'woman',
age: 13,
}
数组类型
type IArr1 = number[];
type IArr2 = Array<string | number | Recode<string, number>>;
type IArr3 = [number, number, string, string];
interface IArr4 = {
[key: number]: any;
}
补充类型
type IEmptyFunction = () => void;
type IAnyType = any;
type INumArr = Array<number>;
泛型
class IMan<T> {
instance: T;
}