const bool : boolean = false;
const num : number = 123;
const num2 : number = 0b11;
const num8 : number = 0o173;
const num16 : number = 0x7b;
const str : string = 'abc';
const str1 : string = `abc${str}`;
const arr : number[] = [1,2,3];
const array : Array<number> = [1,2,3];
const tuple : [string,number,boolean] = ['a',1,false];
enum Roles1 {
SUPER_ADMIN,
ADMIN,
USER
};
console.log(Roles1.SUPER_ADMIN);
enum Roles2 {
SUPER_ADMIN = 1,
ADMIN = 7,
USER = 6
};
console.log(Roles2.SUPER_ADMIN);
enum Roles3 {
SUPER_ADMIN,
ADMIN = 5,
USER
}
console.log(Roles3.USER);
enum Roles4 {
SUPER_ADMIN,
ADMIN = 10,
USER
}
console.log(Roles4[10]);
let any : any = 1;
console.log(any);
any = 'str';
console.log(any);
any = false;
console.log(any);
any = [1,2,3];
console.log(any)
- void类型(不为任何类型,一般用于函数没用返回值)
function fun (text : string) : void {
console.log(text);
}
fun('123');
const a : void = undefined;
const n : null = null;
const u : undefined = undefined;
- never类型(没有不返回任何类型,一般用于函数)
const func = () : never => {
throw new Error('123')
}
const funct = () : never => {
while (true) {}
}
- object类型(个人不推荐使用,后续会介绍对象的声明方法)
const obj : object = {};