我想将每种类型都强制转换为boolean
或object
type CastDeep<T, K = boolean> = {
[P in keyof T]: K extends K[]
? K[]
: T[P] extends ReadonlyArray<K>
? ReadonlyArray<CastDeep<K>>
: CastDeep<T[P]>
}
interface ITest {
city: {
name: string,
}
}
预期结果:
excludeProps<ITest>({
city: true,
});
或
excludeProps<ITest>({
city: {
name: true
},
});
当前错误消息:
19 name: string,
~~~~
The expected type comes from property 'name' which is declared here on type 'CastDeep<{ name: string; }, boolean>'
答案 0 :(得分:2)
好,找到解决方法
export type ICastDeep<T> = {
[P in keyof T]: boolean | ICastDeep<T[P]>;
}