Repository navigation
Type inference has failed by parameter order (regression) #19858
Description
Activity
c:\test\sandbox7>type a.ts declare function f<a>(as1: a[], as2: a[], cmp: (a1: a, a2: a) => number): void; f(Array.from([0]), [], (a1, a2) => a1 - a2); f(Array.from([]), [0], (a1, a2) => a1 - a2); c:\test\sandbox7>tsc --v Version 2.7.0-dev.20171109 c:\test\sandbox7>tsc a.ts --lib es6 c:\test\sandbox7>echo %ERRORLEVEL% 0
I think your example is not correct, and you are looking at a result of #19745.
- addedNeeds More InfoThe issue still hasn't been fully clarifiedThe issue still hasn't been fully clarified
on Nov 9, 2017 falsandtru commented
on Nov 9, 2017 ContributorAuthorMore actionsc:\test\sandbox7>tsc a.ts --lib es6
You have to enable strictNullChecks option.
falsandtru commented
on Nov 9, 2017 ContributorAuthorMore actionsyou are looking at a result of #19745.
Seems like your are right but this result is bad. Anders Hejlsberg (@ahejlsberg) Is this your intended result?
- addedWorking as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bugand removedNeeds More InfoThe issue still hasn't been fully clarifiedThe issue still hasn't been fully clarified
on Nov 9, 2017 #19745 fixes a legitimate issue. However, I do agree that the exhibited behaviour here is also a bug.
The problem is that
Array.from([])should either be:- contextually typed
- inferred as
<T> T[], i.e. an array of a "to be specified" generic type
Currently the call to
Array.fromis eagerly resolved toArray.from<{}>while before it was incorrectly resolved toArray.from<never>.In any case, the root cause is #9366.
It is indeed a regression caused by #19745 where we make no inferences from the
neverelement type of an empty array literal. Another way we could solve #19576 (the issue addressed by #19745) is to give inferences from the element type of empty array literals lower priority than all other inferences. That would still fix #19576 but wouldn't affect the code in this issue.- addedBugA bug in TypeScriptA bug in TypeScriptand removedWorking as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
on Nov 10, 2017 falsandtru commented
on Nov 10, 2017 ContributorAuthorMore actionsThanks!
- addedFixedA PR has been merged for this issueA PR has been merged for this issue
on Nov 10, 2017 - locked and limited conversation to collaborators
on Jun 14, 2018
Intended degradation?
cc Anders Hejlsberg (@ahejlsberg)
TypeScript Version: master
Code
Expected behavior:
no error
Actual behavior: