zl程序教程

您现在的位置是:首页 >  前端

当前栏目

[Typescript] Making TypeScript Stick - 5 - Extends

typescript extends making
2023-09-14 09:00:45 时间

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