Skip to content

globalThis property access errors are behind noImplicitAny, not noImplicitThis #30139

Closed
@sandersn

Description

@sandersn

Now that globalThis is available, top-level this also has a more precise type, and issues the normal noImplicitAny element access errors for unknown properties:

if (this['unknown']) { ... } // error, `typeof globalThis` has no index signature
if (this.unknown) { ... } // error, `typeof globalThis` has no index signature
this.onmousemove = function () { /* ok, and this: Window */ }

We have a conflict: traditionally, "x has no index signature" errors are produced when noImplicitAny is on. Also traditionally, "this has type any" errors are produced when noImplicitThis is on.

Technically, top-level this no longer has type any, so it's technically correct to issue the errors from behind noImplicitAny. But people might expect to see them only when noImplicitThis is on instead.

Let's discuss at the next design meeting.

Metadata

Metadata

Assignees

Labels

In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions