-
Object
范围太广
-
object
:Object除去基本类型之外的类型
索引签名
Record
-
Class
or Constructor
type A = {
[k:string] : number
}
type Record<K extends number | string | symbol, T> = {
[k in K] : T
}
const person: Record<string,number> = {
name: 'frank',
age: 12
}
type Person = {
username: string
age: number
sayHi: FnWithThis
}
type FnWithThis = (this:Person,name) => void
const sayHi:FnWithThis = function(){
console.log(this.username)
}
const person:Person = {
username: 'frank',
age: 12,
sayHi: sayHi
}
// 调用必须指定this
person.sayHi() // 'frank'
or
sayHi.call(person) // 'frank'
-
never
:侧重于类型推导,推到不可能出现的情况,就是never
type A = string | number | boolean
let a:A
if(typeof a === 'string'){
a.indexOf
}else if(typeof a === "number"){
a.toFixed
}else if(typeof a === "boolean"){
a.valueOf
}else{
a // type is never
}