You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
globalThis sometimes being stripped from type emition can leads to errors in emited definition #48783
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
It looks like this applies to in any case where the function type is inferred from an arrow function (and probably function expression too?). The below shows a number of variations that break in d.ts emit, but also show the wrong thing in the tooltip (shown via // ^?). It also affects things if you have (foo: number, bar: typeof globalThis.foo) or something.
The main issue seems to be that we don't set the enclosingDeclaration to the arrow function when converting its signature to a type node; doing so almost fixes the bug but changes all sorts of other tests (honestly, many in positive ways, with a few confusing breaks). However, we then emit global.fetch (or similar) and not globalThis.fetch. The former errors out saying that global is not available.
You can actually see this result if you declare something at the module level with the same name; then we do the right thing (because we see the arrow function's parent and decide to write it explicitly) except that globalThis becomes global which is weird. My example above shows this if the last line is uncommented.
Activity
jakebailey commentedon Jun 21, 2022
It looks like this applies to in any case where the function type is inferred from an arrow function (and probably function expression too?). The below shows a number of variations that break in
d.tsemit, but also show the wrong thing in the tooltip (shown via// ^?). It also affects things if you have(foo: number, bar: typeof globalThis.foo)or something.Playground Link
The main issue seems to be that we don't set the enclosingDeclaration to the arrow function when converting its signature to a type node; doing so almost fixes the bug but changes all sorts of other tests (honestly, many in positive ways, with a few confusing breaks). However, we then emit
global.fetch(or similar) and notglobalThis.fetch. The former errors out saying thatglobalis not available.You can actually see this result if you declare something at the module level with the same name; then we do the right thing (because we see the arrow function's parent and decide to write it explicitly) except that
globalThisbecomesglobalwhich is weird. My example above shows this if the last line is uncommented.