Within one specific file, there is a structured code block like the following:
export const _total = {
a: '',
b: '',
c: '',
d: '',
e: '',
f: '',
}
type TotalKeysType = typeof _all;
export type TotalKey = keyof TotalKeysType;
In a separate file, there exists the following code structure:
export const _retain = {
a: '',
b: '',
d: '',
e: '',
}
type RetainKeysType = typeof _retain;
export type RetainKey = keyof RetainKeysType;
export const _deny = {
c: '',
f: '',
}
type DenyKeysType = typeof _deny;
export type DenyKey = keyof DenyKeysType;
Is it possible to utilize Typescript in guaranteeing that the keys specified in _total
are always equivalent to the combination of keys from both _retain
and _deny
? Essentially, ensuring that TotalKey
always matches RetainKey
| DenyKey
.
The intention here is to have the Typescript compiler raise an error if a developer adds a new value (for instance, z
) to _total
, while neglecting to include z
within either _retain
or _deny
.