You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes, we want to enforce that only one property from a set of properties can be used at a time.
For example:
typeA={a: string};typeB={b: string};functiondoSomething(input: A|B){// do something}
In this case, the union type A | B allows us to pass either A or B, but it also allows both properties (a and b) to coexist, which might not be what we want.
To ensure that exactly one property is used, we can use RequiredExactlyOne.
typeExample={a: ()=>string;b: ()=>string;};constexample: RequiredExactlyOne<Example,'a'|'b'>={// Adding both `a` and `b` would cause a compile error.b: ()=>{console.log(1);}};
RequiredExactlyOne ensures that only one of the specified properties is present, preventing potential conflicts when multiple properties could be passed at the same time.
The text was updated successfully, but these errors were encountered:
This introduces support for
RequiredExactlyOne
.Sometimes, we want to enforce that only one property from a set of properties can be used at a time.
For example:
In this case, the union type
A | B
allows us to pass eitherA
orB
, but it also allows both properties (a
andb
) to coexist, which might not be what we want.To ensure that exactly one property is used, we can use
RequiredExactlyOne
.RequiredExactlyOne
ensures that only one of the specified properties is present, preventing potential conflicts when multiple properties could be passed at the same time.The text was updated successfully, but these errors were encountered: