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
ChainedAccessUnion查找可读路径,如果对象里面某个key的值为数组,会把数组的方法也当成联合类型
The text was updated successfully, but these errors were encountered:
理论上,数组的方法也是可以访问的,如果你需要移除数组的方法,再生成"可读路径"类型,可以先将数组类型转为"类数组"类型
type TransformArrayToArrayLikeDeep<T> = T extends object ? { [Key in keyof T]: T[Key] extends Array<any> ? { [ArrKey in keyof T[Key] as ArrKey extends 'length' | `${number}` ? ArrKey : never]: TransformArrayToArrayLikeDeep<T[Key][ArrKey]> } : TransformArrayToArrayLikeDeep<T[Key]> } : T
然后,
interface YourObject { a: 1, b: 2, c: [{ d: [1] }, 2, 3] } // "a" | "b" | "c" | "c.length" | "c.0" | "c.1" | "c.2" | "c.0.d" | "c.0.d.length" | "c.0.d.0" type Result = ChainedAccessUnion<TransformArrayToArrayLikeDeep<YourObject>>
Sorry, something went wrong.
No branches or pull requests
ChainedAccessUnion查找可读路径,如果对象里面某个key的值为数组,会把数组的方法也当成联合类型
The text was updated successfully, but these errors were encountered: