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 DeepReadOnly<Obj extends Record<string, any>> = { readonly [Key in keyof Obj]: Obj[Key] extends object ? Obj[Key] extends Function ? Obj[Key] : DeepReadOnly<Obj[Key]> : Obj[Key] } type deepReadOnly = DeepReadOnly<{ a: string b: number c: { d: number e: { name: string } } }>
因为 ts 的类型只有被用到的时候才会做计算。
所以可以在前面加上一段 Obj extends never ? never 或者 Obj extends any 等,从而触发计算:
type DeepReadOnly<Obj extends Record<string, any>> = Obj extends any ? { readonly [Key in keyof Obj]: Obj[Key] extends object ? Obj[Key] extends Function ? Obj[Key] : DeepReadOnly<Obj[Key]> : Obj[Key] } : never
The text was updated successfully, but these errors were encountered:
No branches or pull requests
就比如这种
因为 ts 的类型只有被用到的时候才会做计算。
所以可以在前面加上一段 Obj extends never ? never 或者 Obj extends any 等,从而触发计算:
The text was updated successfully, but these errors were encountered: