Skip to content

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

Closed
@LeonardDrs

Description

@LeonardDrs

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

export const fetchSomething = (
	fetch: typeof globalThis.fetch
): typeof globalThis.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

export declare const fetchSomething: (fetch: typeof fetch) => typeof fetch;

🙂 Expected behavior

Generated d.ts file should keep the reference to globalThis

export declare const fetchSomething: (fetch: typeof globalThis.fetch) => typeof globalThis.fetch;

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

export type FetchSomething = {
	fetch: typeof globalThis.fetch
}

export class FetchSomethingClass {
	fetch?: typeof globalThis.fetch
}

export type FetchSomethingFunction = (fetch: typeof globalThis.fetch) => typeof globalThis.fetch

// .d.ts
export declare type FetchSomething = {
    fetch: typeof globalThis.fetch;
};
export declare class FetchSomethingClass {
    fetch?: typeof globalThis.fetch;
}
export declare type FetchSomethingFunction = (fetch: typeof globalThis.fetch) => typeof globalThis.fetch;

🤔 Workaround

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

export const fetchSomething: (fetch: typeof globalThis.fetch) => typeof globalThis.fetch = (fetch) => fetch;

Metadata

Metadata

Assignees

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