Skip to content

globalThis sometimes being stripped from type emition can leads to errors in emited definition #48783

Description

Bug Report

🔎 Search Terms

globalThis, removed, remove, stripped, 2502, own type annotation, referenced, definition, .d.ts

🕗 Version & Regression Information

  • This is the behavior in every version I tried, since 3.5.1, and I reviewed the FAQ for entries about globalThis, 2502, own type annotation

⏯ Playground Link

Playground link with relevant code, mainly using the D.TS tab

💻 Code

exportconstfetchSomething=(fetch: typeofglobalThis.fetch): typeofglobalThis.fetch=>fetch

🙁 Actual behavior

This code will generate the following .d.ts file, which contains the 'fetch' is referenced directly or indirectly in its own type annotation. (2502) error

exportdeclareconstfetchSomething: (fetch: typeoffetch)=>typeoffetch;

🙂 Expected behavior

Generated d.ts file should keep the reference to globalThis

exportdeclareconstfetchSomething: (fetch: typeofglobalThis.fetch)=>typeofglobalThis.fetch;

as it does when declaring a function, type or class:

exporttypeFetchSomething={fetch: typeofglobalThis.fetch}exportclassFetchSomethingClass{fetch?: typeofglobalThis.fetch}exporttypeFetchSomethingFunction=(fetch: typeofglobalThis.fetch)=>typeofglobalThis.fetch// .d.tsexportdeclaretypeFetchSomething={fetch: typeofglobalThis.fetch;};exportdeclareclassFetchSomethingClass{fetch?: typeofglobalThis.fetch;}exportdeclaretypeFetchSomethingFunction=(fetch: typeofglobalThis.fetch)=>typeofglobalThis.fetch;

🤔 Workaround

Typing the const instead of the anonymous function works as expected.

exportconstfetchSomething: (fetch: typeofglobalThis.fetch)=>typeofglobalThis.fetch=(fetch)=>fetch;

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions