Repository navigation
Type inference for generic functions #11537
Copy link
Copy link
Closed
Labels
FixedA PR has been merged for this issueA PR has been merged for this issue
Description
Activity
might be
dupa new shiny case of #3038Reacted by Sergey Shandarsergey-shandar commented
on Oct 11, 2016 ContributorAuthorMore actionsIf it's compatibility problem, it would be really helpful to have a "strictTyping" compilation mode which would prohibit converting the
anytype to other types without explicit cast.Reacted by Sergey Shandarthey say without
anyit will be an infinite recursion which i don't get because an explicit lambda (v => vin your case) doesn't have this problem, if so.. why would not TS handle all function references as explicit lambdas behind the scenes to avoid this recursion problemsergey-shandar commented
on Oct 11, 2016 ContributorAuthorMore actionsAn ugly workaround
function getId<T>(): (v: T) => T { return v => v; } applyToNumber(5, getId()); // error, can't infer the 'T' type. applyToNumber(5, getId<number>()); // ok but 'v => v' looks better.
looks like its time to bite that bullet or else you gonna break that all time record of the number of open issues related to the same problemo
- addedNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
on May 24, 2017 The sample given:
applyToNumber("aaa", id); // ok, but an error is expected.
in TS 2.6 returns error:
Argument of type '<T>(v: T) => T' is not assignable to parameter of type '(x: string) => number'. Type 'string' is not assignable to type 'number'.So I assume it's fixed.
Reacted by Sergey Shandar- addedFixedA PR has been merged for this issueA PR has been merged for this issueand removedNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
on Nov 13, 2017 thanks! closing.
- locked and limited conversation to collaborators
on Jun 19, 2018
Metadata
Metadata
Assignees
Labels
FixedA PR has been merged for this issueA PR has been merged for this issue
TypeScript Version: 2.0.3
Code
Expected behavior:
error
Actual behavior:
no error.