Skip to content

In JS, noImplicitThis puts an error on this inside a constructor function #25979

Description

TypeScript Version: 30c4149

Search Terms:
jsdoc @constructor this
Code

/** @constructor */ function Example() { this.m = 1; }
/** @constructor */ var Example2 = function() { this.j = 2; };

Compiled with --allowJs --checkJs --noImplicitThis

Expected behavior:
Compiles fine.

Actual behavior:

error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.

Playground Link:
https://www.typescriptlang.org/play/#src=%2F**%20%40constructor%20*%2F%20function%20Example()%20%7B%20this.m%20%3D%201%3B%20%7D%0D%0A%2F**%20%40constructor%20*%2F%20var%20Example2%20%3D%20function()%20%7B%20this.j%20%3D%202%3B%20%7D%3B%0D%0A

Activity

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

    FixedA PR has been merged for this issueSuggestionAn idea for TypeScriptcheckJsRelates to checking JavaScript using TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions