//interface 定义对象结构测试
interface abc {
a: string,
b: number,
c?: Array<String>
}
interface cbd extends abc {
alert: Function
};
// class用来实现抽象接口的具体行为
class mycls implements cbd {
a: string;
b: number;
static c:number=2342343234;
constructor(){
this.a="sykdfjsldfsdf"
this.b=23424234
console.log(this.b,"vsslkdjfskfsdfkjsl")
}
alert() {
console.log(this.alert, "slkfjlskdfjlskfd")
}
static fn1(){
console.log(this.c,"slkfjslkfjslkdf")
}
}
console.log("test")
mycls.fn1()
interface result{
msg:string,
code:number,
data:any
}
//type 定义数据类型测试
type ddd=abc & {
d:result
}
let dddDemo:ddd={
a:"ksjflksdfs",
b:23423423434,
d:{
msg:"成功",
code:0,
data:{}
}
}
console.log(dddDemo,"dddDemo")
interface eee extends ddd{
}
//interface接口用来描述对象结构
let myobj1:eee={
a:'234234242',
b:234234234,
d:{
msg:"成功",
code:0,
data:{}
}
}
console.log(myobj1,"myobj1")
enum RouterSource{
Frontend = 'frontend',
Backend = 'backend'
}
enum myenum{
FALSE=0,
TRUE=1
} //说明枚举也是用来限定数据范围
let enum12:myenum=0;
console.log(enum12,"enum12")
function myfanxing<T>(a:T):Array<T>{
let abc:T=a;
return [abc]
}
let mmmm:unknown;
mmmm=<string>"slkfjsdljsdf" //类型断言
let uuu=myfanxing<string>(mmmm as string) //类型断言
console.log(uuu,"uuu")
标签:abc,console,log,ts,number,语法,let,测试,interface
From: https://www.cnblogs.com/jocongmin/p/18220526