-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
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
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;
PaulCailly and ExE-BossPaulCailly and ExE-Boss
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone