Includes [array]
在类型系统里实现 JavaScript 的 Array.includes 方法,这个类型接受两个参数,返回的类型要么是 true 要么是 false。
type isPillarMen = Includes<['Kars', 'Esidisi', 'Wamuu', 'Santana'], 'Dio'> // expected to be `false`
/**
* 思路:
* 1 利用 extends来约束 T 为数组 U 可以理解为即将校验的包含项
* 2 定义个数组类型 定义一个
*/
type Includes<T extends readonly any[], U> = T extends [infer A, ...infer Rest]
? Equal<A, U> extends true
? true
: Includes<Rest, U>
: false;