Skip to content
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

This typing for callbacks typed as any #10972

Closed
tinganho opened this issue Sep 18, 2016 · 5 comments
Closed

This typing for callbacks typed as any #10972

tinganho opened this issue Sep 18, 2016 · 5 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@tinganho
Copy link
Contributor

I don't quite understand why below code is typed as any(I'm using nightly with --noImplicitThis)?

interface A {
    a: string;
}
declare function test(callback: (this: A) => void): void;
test(function() {
    this.a;// typed as any?
});
@sandersn
Copy link
Member

This works for me when I paste this into a VS Code instance running on a branch that I merged from master on Thursday. Let me try the current master...do you have another repro besides this snippet?

@sandersn
Copy link
Member

sandersn commented Sep 19, 2016

Never mind, I was actually running code from July. It's broken once I point VS to the Thursday-updated branch.

@mhegazy mhegazy added the Bug A bug in TypeScript label Sep 19, 2016
@mhegazy mhegazy added this to the TypeScript 2.1 milestone Sep 19, 2016
@sandersn
Copy link
Member

In case I want to git bisect later, July 6 was the time that the "works-for-me" branch was last merged from master.

@sandersn
Copy link
Member

I suspect this PR: #9746
I'll investigate later.

@mhegazy mhegazy modified the milestones: TypeScript 2.1, Future Sep 29, 2016
@mhegazy mhegazy modified the milestones: TypeScript 2.1, Future Oct 7, 2016
@sandersn
Copy link
Member

So, interestingly, this is a bug only in quick info and listing members. Change the callback to return A and you will see that errors are still caught:

interface A {
    a: string;
}
declare function noThis(callback: (this: A) => A): A;
noThis(function() { // error, 'string' is not assignable to 'A'
    return this.a + this.nope; // error, 'nope' does not exist on 'A'
});

I still suspect #9746.

sandersn added a commit that referenced this issue Oct 17, 2016
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Oct 18, 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 Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants