// Here's a way to define types in TypeScript:
interface SudoA {
foo: string;
}
interface SudoB {
bar: string;
}
type Sudo = SudoA | SudoB;
type SuperSudo = Sudo & {
super: boolean;
}
const baz: SuperSudo = {
}
// TypeScript (3.1.6) requires both `bar` and `foo` properties to be defined in the object
My expectation is to make the super
attribute required while allowing other attributes from the Sudo
type to be optional. Is this a valid expectation? If not, how can this be achieved?
Edit
I corrected the type of baz
, my mistake :/.
I want SuperSudo
to only require the super
attribute while making other attributes optional.
One approach is to create a new type like
type SuperSudo<T> = T & {}
but this results in using SuperSudo<T>
which I find too verbose.
Edit2
Title has been updated