Skip to content

this any typed in some JS object literals  #22058

Open

Description

@mjbvz

From microsoft/vscode#43930

TypeScript Version: 2.8.0.insiders-20180211

Search Terms:

  • this
  • object literal

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:

Activity

  1. rubiesonthesky commented on Mar 10, 2024

    @rubiesonthesky

    This is still an issue. Repro

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

    Workbench Repro

  2. typescript-bot commented on Mar 11, 2024

    @typescript-bot
    Contributor

    👋 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

    ‼️ Exception: Error - error TS5107: Option 'moduleResolution=node10' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error. Visit https://aka.ms/ts6 for migration information.

    Error: error TS5107: Option 'moduleResolution=node10' is deprecated and will stop functioning in TypeScript 7.0. Specify compilerOption '"ignoreDeprecations": "6.0"' to silence this error.
      Visit https://aka.ms/ts6 for migration information.
    
        at Object.createVirtualTypeScriptEnvironment (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:8128:11)
        at twoslasher (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:7618:17)
        at /home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:439:44
        at runTwoslashRequests (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:406:56)
        at run (/home/runner/work/_actions/microsoft/TypeScript-Twoslash-Repro-Action/master/dist/index.js:20096:75)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    

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

    ⚠️ Assertions:

    • any

    ⚠️ Way slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JavaScriptThe issue relates to JavaScript specificallyHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-reprosVS Code TrackedThere is a VS Code equivalent to this issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions