Open yunliuyan opened 11 months ago
number将元素遍历出来
type Includes<T extends readonly any[], U extends any> = U extends T[number] ? true : false
type isPillarMen = Includes<['Kars', 'Esidisi', 'Wamuu', 'Santana'], 'Dio'> // expected to be `false`
type Includes<T extends readonly any[], P extends any> = {
[k in T[number]]: true;
}[P] extends true ? true : false;
type isPillarMen = Includes<['Kars', 'Esidisi', 'Wamuu', 'Santana'], 'Dio'> // expected to be `false`
// 在类型系统里实现 JavaScript 的 Array.includes 方法,这个类型接受两个参数,返回的类型要么是 true 要么是 false。
type Includes<T extends any[], K> = K extends T[number] ? true : false;
type isPillarMen = Includes<['Kars', 'Esidisi', 'Wamuu', 'Santana'], 'xxx'> // expected to be `false`
Includes
![#array](https://img.shields.io/badge/-%23array-999)
在类型系统里实现 JavaScript 的
Array.includes
方法,这个类型接受两个参数,返回的类型要么是true
要么是false
。例如: