I have a type with some possibly undefined fields
type Foo = {
a: string | undefined
b: string
c: string | undefined
}
I want the same type, but declaring that none of the fields are undefined
type Bar = {
a: string
b: string
c: string
}
I'd like a way to derive Bar from Foo, so that I don't have to manually create Bar and update it when Foo changes. Something like this
type Bar = NoPropertiesUndefined<Foo>
Is there any generic like this built into Typescript?
A note on usecase - I'm using this when I get the type Foo as an input, then validate it to check no fields are undefined, then pass to another function for further processing. I'd like that other function to take a Bar argument, and have the validator return a Bar or throw, to ensure I've validated the Foo in a typesafe way. The Foo types can even be dynamically created themselves using ReturnType - so even the cumbersome nature of manually defining Bar aside, in some cases it's not even possible.