[Typescript] Making TypeScript Stick - 5 - Extends
作者:互联网
Let’s study a few examples of extends
scenarios and see if we can figure out whether it will evaluate to true
or false
64 extends number
.
.
.
Answer:
查看代码
true
number extends 64
.
.
.
Answer:
查看代码
false
string[] extends any
.
.
.
Answer:
查看代码
true
// does any contians string[] --- yes it is
string[] extends any[]
.
.
.
Answer:
查看代码
true
// does any[] contains string[] --- yes it is
never extends any
.
.
.
.
Answer:
查看代码
true
// yes, any can contain never type
any extends any
.
.
.
Answer:
查看代码
true
Date extends {new (...args: any[]): any }
.
.
.
.
Answer:
false
// Date is instance type
// does not extends constructor()
(typeof Date) extends {new (...args: any[]): any }
.
.
.
.Answer:
查看代码
true
// typeof Date is a constructor type
标签:TypeScript,查看,代码,Typescript,extends,Answer,Making,true,any 来源: https://www.cnblogs.com/Answer1215/p/16586884.html