🔎 Search Terms
"constraint evaluation", "type infer"
🕗 Version & Regression Information
- This changed between versions 4.9 and 5.0
In Version 5.x, parentheses changes the result of type inference;
In Version 4.9 - 4.7(The minimum version that supports infer X extends ...), parentheses not changes the result of type inference;
⏯ Playground Link
playground link
💻 Code
typePositiveInfinity=1e999;typeNegativeInfinity=-1e999;exporttypeIsEqual<A,B>=(<G>()=>GextendsA ? 1 : 2)extends(<G>()=>GextendsB ? 1 : 2)
? true
: false;exporttypeAdd<Aextendsnumber,Bextendsnumber>=[IsEqual<A,PositiveInfinity>,IsEqual<A,NegativeInfinity>,IsEqual<B,PositiveInfinity>,IsEqual<B,NegativeInfinity>,]extends infer Rextends[boolean,boolean,boolean,boolean]
? [true,false]extends([R[0],R[3]])// Note: with parentheses
? PositiveInfinity
: 'failed'
: never;exporttypeAddWithoutParentheses<Aextendsnumber,Bextendsnumber>=[IsEqual<A,PositiveInfinity>,IsEqual<A,NegativeInfinity>,IsEqual<B,PositiveInfinity>,IsEqual<B,NegativeInfinity>,]extends infer Rextends[boolean,boolean,boolean,boolean]
? [true,false]extends[R[0],R[3]]// Note: without parentheses
? PositiveInfinity
: 'failed'
: never;typeAddTest0=Add<PositiveInfinity,PositiveInfinity>;// failedtypeAddTest1=AddWithoutParentheses<PositiveInfinity,PositiveInfinity>;// in version 5.x: "Infinity"; but in version 4.x, it's "failed"
🙁 Actual behavior
typeAddTest0=Add<PositiveInfinity,PositiveInfinity>;// "failed" (both in version 4.x and 5.x, it is)typeAddTest1=AddWithoutParentheses<PositiveInfinity,PositiveInfinity>;// "Infinity" in version 5.x; but in version 4.x, it's "failed"
🙂 Expected behavior
// Better be able to do:typeAddTest0=Add<PositiveInfinity,PositiveInfinity>;// Infinity (both in version 4.x and 5.x)typeAddTest1=AddWithoutParentheses<PositiveInfinity,PositiveInfinity>;// Infinity (both in version 4.x and 5.x)// at least:typeAddTest0=Add<PositiveInfinity,PositiveInfinity>;// failed (both in version 4.x and 5.x)typeAddTest1=AddWithoutParentheses<PositiveInfinity,PositiveInfinity>;// failed (both in version 4.x and 5.x)
Additional information about the issue
see also: #51090
🔎 Search Terms
"constraint evaluation", "type infer"
🕗 Version & Regression Information
In Version 5.x, parentheses changes the result of type inference;
In Version 4.9 - 4.7(The minimum version that supports
infer X extends ...), parentheses not changes the result of type inference;⏯ Playground Link
playground link
💻 Code
🙁 Actual behavior
🙂 Expected behavior
Additional information about the issue
see also: #51090