以下类型定义存在一些问题。
type Check<T> = (value: any) => value is T;
type Static<T> = T extends Check<infer U> ? U : never;
type Interface<T extends { [index: string]: Check<any> }> = Check<{ [P in keyof T]: Static<T[P]> }>;
type IPlayer = Static<
Interface<{
name: Check<string>;
data: Interface<{
score: Check<number>;
}>;
}>
>;
使用TypeScript 3.1.1,如果将鼠标悬停在VS Code中的IPlayer
上,它将类型解析为:
type IPlayer = {
name: string;
data: any;
}
但是,我希望它解决:
type IPlayer = {
name: string;
data: {
score: number;
};
}
如何更改我的类型定义以使其正常工作?