Skip to content

Generic type inference does not appear to fill in type of this parameter #10072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Aug 1, 2016 · 1 comment
Closed
Assignees
Labels
Bug A bug in TypeScript Duplicate An existing issue was already created

Comments

@ghost
Copy link

ghost commented Aug 1, 2016

TypeScript Version: nightly

Code

function f<T>(x: T, f: (x: T) => string): void {}
f("", x => x);

function g<T>(x: T, f: (this: T) => string): void {}
g<string>("", function() { return this; });
g("", function() { return this; });

Expected behavior:

No error. this is always of type string.

Actual behavior:

In the last line, the type of this is still T; it hasn't been 'filled in'.

src/a.ts(6,7): error TS2345: Argument of type '() => T' is not assignable to parameter of type '(this: string) => string'.
  Type 'T' is not assignable to type 'string'.
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Aug 2, 2016
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 2.1 milestone Aug 2, 2016
@sandersn
Copy link
Member

sandersn commented Aug 2, 2016

Duplicate of #9673 with a proposed fix at #9746.

@sandersn sandersn added the Duplicate An existing issue was already created label Aug 2, 2016
@sandersn sandersn closed this as completed Aug 2, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants