在一个文件中,我有这样的内容:
export const _all = {
a: '',
b: '',
c: '',
d: '',
e: '',
f: '',
}
type AllKeysType = typeof _all;
export type AllKey = keyof AllKeysType;
在另一个文件中,我有这样的东西:
export const _keep = {
a: '',
b: '',
d: '',
e: '',
}
type KeepKeysType = typeof _keep;
export type KeepKey = keyof KeepKeysType;
export const _ignore = {
c: '',
f: '',
}
type IgnoreKeysType = typeof _ignore;
export type IgnoreKey = keyof IgnoreKeysType;
如何使用 Typescript 断言_allALWAYS 中定义的键等于 and 的_keep并集_ignore。换句话说,AllKey应该总是等于KeepKey| IgnoreKey.
_all我希望 Typescript 编译器在开发人员通过添加新值(比如z)进行更新但忘记添加z到_keepor时给我一个错误_ignore。