In one file I have something like this:
export const _all = {
a: '',
b: '',
c: '',
d: '',
e: '',
f: '',
}
type AllKeysType = typeof _all;
export type AllKey = keyof AllKeysType;
In another file I have something like this:
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;
How can I use Typescript to assert that the keys defined in _all
ALWAYS is equal to the union of _keep
and _ignore
. In other words, AllKey
should always be equal to KeepKey
| IgnoreKey
.
I want the Typescript compiler to give me an error if a developer updates _all
by adding in a new value (say z
) but forgets to add z
into either _keep
or _ignore
.