Open Hideman85 opened 2 years ago
Can't you just let options
be typed automatically, and enforce the return type of your buildOptions
function instead?
function buildOptions(required: boolean, name: string, team?: string): Options {
const options = {
required,
filters: {
name,
},
};
if (team) {
options.filters.team = team;
}
return options;
}
In this way you do not get the other properties neither the real type of them 'foo' | 'bar' !== string
.
I have really no idea how to call this helper, but let me describe the use case.
Please let me know if that make sense and if you could help me to build this helper. I think this become pretty useful when the type has plenty of props and you just want to define them and infer the correct typing.
Thanks in advance for your help.
Upvote & Fund