标签:callee 实现 not last htm number use must static
在原生的JS里,null和undefined经常会导致BUG的产生,
在ts里,你又想用null,又担心出错的时候
你可以考虑用联合类型,当某值可能为 number或null,你可以声明它的类型为number | null
let a : number | null = 2;
实现接口时,只要包含了接口要求的数据结构即可兼容这个接口
interface Person {
firstName: string;
lastName: string;
}
function greeter(person: Person) {
return "Hello, " + person.firstName + " " + person.lastName;
}
let user = { firstName: "Jane", lastName: "User" };
document.body.innerHTML = greeter(user);
继承( extends关键字 )
public private protected static readonly get和set 都有,连namespace也有;
抽象类( abstract关键字 )
let deck: Deck = {
// NOTE: The function now explicitly specifies that its callee must be of type Deck
createCardPicker: function(this: Deck) {
return () => {
console.log(this)
}
}
}
指明this的类型必须是Deck
function identity<T>(arg: T): T {
return arg;
}
let output = identity<string>("myString"); // type of output will be ‘string‘
//或者
let output = identity("myString"); // type of output will be ‘string‘
泛型方法、泛型类、泛型约束都有
标签:callee 实现 not last htm number use must static
原文地址:https://www.cnblogs.com/liulun/p/11044436.html