TypeScript:获取 Class 的非继承属性
TypeScript: Get Non-Inherited Properties of Class
class A {
baseField: number;
}
class B extends A {
nonInherited: number;
}
type onlyNonInherited = PickNonInherited<B>;
我需要我的 onlyNonInherited
类型等于以下内容:
interface NonInherited {
nonInherited: number;
}
PickNonInherited
的定义应该是什么?
我试过阅读很多帖子,但没有找到解决方案:(
仅查看类型 B
无法做到这一点。但是你可以做类似
的事情
type OnlyNonInherited = Omit<B, keyof A>;
class A {
baseField: number;
}
class B extends A {
nonInherited: number;
}
type onlyNonInherited = PickNonInherited<B>;
我需要我的 onlyNonInherited
类型等于以下内容:
interface NonInherited {
nonInherited: number;
}
PickNonInherited
的定义应该是什么?
我试过阅读很多帖子,但没有找到解决方案:(
仅查看类型 B
无法做到这一点。但是你可以做类似
type OnlyNonInherited = Omit<B, keyof A>;