microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.7k stars 12.45k forks source link

this any typed in some JS object literals #22058

Open mjbvz opened 6 years ago

mjbvz commented 6 years ago

From https://github.com/Microsoft/vscode/issues/43930

TypeScript Version: 2.8.0.insiders-20180211

Search Terms:

Code For the js:

console.log({
    a: 1,
    b() {
        this
  }
});

Hover over this in b

Bug this has any type

this is properly typed in cases like:

const z = {
    a: 1,
    b() {
        this
  }
}

Playground Link:

Related Issues:

rubiesonthesky commented 7 months ago

This is still an issue. Repro

console.log({
    a: 1,
    b() {
        this
//      ^?
  }
});

Workbench Repro

typescript-bot commented 7 months ago

:wave: Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of this repro running against the nightly TypeScript.


Comment by @rubiesonthesky

:warning: Assertions:

Historical Information
Version Reproduction Outputs
5.0.2, 5.1.3, 5.2.2, 5.3.2, 5.4.2

:warning: Assertions:

  • any