Trying to define a type that can be one of two options, currently attempting the following:
type TestConfig = {
file: string;
name: string;
}
type CakeConfig = {
run: string;
}
type MixConfig = { test: TestConfig | CakeConfig };
const typeCheck: MixConfig = {
test: {
run: 'run!'
}
};
console.log(typeCheck.test.run)
However, encountering a type checking error:
Property 'run' does not exist on type 'TestConfig | CakeConfig'. Property 'run' does not exist on type 'TestConfig'.
Assumed that using the union operator would allow for either option, but it seems to not work as expected. Any suggestions on how to achieve a similar result? The scenario is where the type could be one of the options without prior knowledge.
Thank you!