We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
type IsEqual<A, B> = (<X>() => X extends A ? 1 : 2) extends <X>() => X extends B ? 1 : 2 ? true : false; type Includes<T extends unknown[], U> = T extends [infer F, ...infer Rest] ? IsEqual<F, U> extends true ? true : Includes<Rest, U> : false; // number extends T['length']排除非元组类型,因为T有可能是string[] // type arr1 = string[] -> arr1['length'] -> number // type arr2 = [string] -> arr2['length'] -> 1 type CheckRepeatedTuple<T extends unknown[]> = number extends T["length"] ? false : // 递归遍历T,每次取出第一项 T extends [infer F, ...infer Rest] ? // 判断后面的所有成员中是否有与第一项相等的 Includes<Rest, F> extends true ? true : // 如果没有,继续递归后面的所有成员,此时第一项可以排除了 CheckRepeatedTuple<Rest> : false;
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: