GeezerVison is showing github.com — Make functions generic when contextually typed by a generic signature · Issue #5737 · microsoft/TypeScript
Make functions generic when contextually typed by a generic signature #5737
Description
type Foo = (one: string) => number;
function fooOver() : Foo {
return one => parseInt(one); // <-- one is string
}
type Bar = <a>(one: string) => a;
function barOver() : Bar {
return one => parseInt(one); // <-- one is god knows what
}
Activity
RyanCavanaugh commented on Nov 20, 2015
Technically this is according to per spec (I know, your favorite response), but I think we should do better here.
Section 4.2.3 (https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#423-contextually-typed-expressions) says
In the body of a function expression or arrow function that has no return type annotation, if the function expression or arrow function is contextually typed by a function type with exactly one call signature, and if that call signature is non-generic, return expressions are contextually typed by the return type of that call signature.
We already said that we should contextually type parameters when type annotations are present somewhere --- no reason we shouldn't contextually type using the non-generic parameter positions or non-generic return positions.
ahejlsberg commented on Dec 7, 2015
Ryan Cavanaugh (@RyanCavanaugh) There is no easy way to tell whether a particular type references a type parameter and I honestly think that we either contextually type all parameters or none. Anything in between just gets even more confusing.
changed the title
[-]another inferrence strangeness[/-] [+]Make functions generic when contextually typed by a generic signature[/+] on Aug 21, 2016
Metadata
Metadata
Development
No branches or pull requestsIssue actions