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
Apologies if this is a feature and not a bug, but it seems like a bug to me, since you can achieve the desired behavior by writing more runtime code.
TypeScript Version: 3.3.3 (still true in 3.4.0-dev.20190208)
Search Terms:
function argument spread order with union type tuples
Code
typeArgsUnion=[number,string]|[number,Error]typeTupleUnionFunc=(...params: ArgsUnion)=>number// arguments are a union of tuplesconstfuncUnionTupleNoRest: TupleUnionFunc=(num,strOrErr)=>{// (parameter) num: string | number | Errorreturnnum// fails}constfuncUnionTupleRest: TupleUnionFunc=(...params)=>{const[num,strOrErr]=paramsreturnnum// succeeds!}
Expected behavior: num variable should preserve order of tuple types
Actual behavior: funcUnionTupleNoRest does not preserve order of rest parameters on tuple
constfuncUnionTupleNoRest: TupleUnionFunc=(num,strOrErr)=>{// (parameter) num: string | number | Errorreturnnum// fails}
There is a workaround to this by using function overrides instead of union argument types, though they are less convenient because on each function declaration, each parameter needs to be typed individually
Apologies if this is a feature and not a bug, but it seems like a bug to me, since you can achieve the desired behavior by writing more runtime code.
TypeScript Version: 3.3.3 (still true in 3.4.0-dev.20190208)
Search Terms:
function argument spread order with union type tuples
Code
Expected behavior:
num
variable should preserve order of tuple typesActual behavior:
funcUnionTupleNoRest
does not preserve order of rest parameters on tupleThere is a workaround to this by using function overrides instead of union argument types, though they are less convenient because on each function declaration, each parameter needs to be typed individually
Playground Link: https://www.typescriptlang.org/play/index.html#.....
Related Issues:
The text was updated successfully, but these errors were encountered: