Skip to content

Unable to use global this when noImplicitThis is enabled. #15613

Closed
@david-driscoll

Description

@david-driscoll

When noImplicitThis is turned on, you are unable to reference the global this (which may be window, or global, or other value in various runtime environments).

I'm not sure if there is a recommended way around this, but currently there does not appear to be a way to get the "global" this without an error 'this' implicitly has type 'any' because it does not have a type annotation. This may be something I'm just not seeing. I tried to define global but that wasn't much help.

TypeScript Version: 2.3.x

Code

(function (this: any, root) {
    // do something isolated 
})(<any>this);

Expected behavior:
Be able to use the global this without error.

Actual behavior:
Compiler error 'this' implicitly has type 'any' because it does not have a type annotation. when using this globally.

cc @benlesh

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions