Repository navigation
Generic argument inference no longer working for specific case #39080
Description
Activity
- addedNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
on Jun 15, 2020 Looks to be caused by #37261 - the erased signature seems ok, in theory, but because it erases to
any,any & T1becomes justany, and we lose the ability to infer toT1. If we erase tounknowninstead, this should work -unknownwill still behave likeanyin unions still, though (and prevent inference to other union members), which makes me wonder if erasing to a unique anti-any-type-thing might be better - something which evaporates in both unions and intersections, but otherwise behavesanyish.I'm wondering if this is the same issue (also works in 3.8 and fails in 3.9):
interface Input<V> { v: V } const inner = <V>(fn: <T extends Input<V>>(t: T) => null) => null; export default () => inner(<T extends Input<string>>(t: T) => null); // <-- error here
Calling
inner<string>(...)explicitly works.This shorter example has the same general structure (an argument which is a function with a complicated parameter), but there's too much going on for me to be sure it's the same bug.
- addedRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
on Aug 31, 2020 - addedFix AvailableA PR has been opened for this issueA PR has been opened for this issue
on Sep 4, 2020 1 remaining item
RyanCavanaugh commented
on Feb 15, 2023 MemberMore actionsThis behaves as expected now
TypeScript Version: >3.9.2
Search Terms: generic argument inference TS2345
Code
Expected behavior: In v3.8.3, the code above did not have any compilation error.
Actual behavior: Compilation error TS2345 when I do not explicitly pass the generic type.
Playground Link: Link
Note: I use React, here I only included the minimal React interfaces to reproduce the issue. The issue is also reproducible with React code directly here