Given object A:
interface A {
boolProp: boolean,
stringProp: string,
numberProp: number,
...other props/methods...
}
Now, I need objects that contain one of the properties from A and set a default value for it, with other properties being irrelevant to this context.
interface B {
prop: keyof A,
default: typeof keyof A,
...other props/methods...
}
The goal is to trigger a TypeScript error when attempting to assign a default value of a different type.
const b: B = {
prop: 'stringProp',
default: true, // An error should be raised since true cannot be assigned to a string
};
Thank you in advance for any assistance 🙏