Skip to content

fix: type check failure in import.meta polyfill with newer @types/node - #499

Merged
dsherret merged 1 commit into
denoland:mainfrom
dsherret:fix_import_meta_polyfill_types
Jul 26, 2026
Merged

fix: type check failure in import.meta polyfill with newer @types/node#499
dsherret merged 1 commit into
denoland:mainfrom
dsherret:fix_import_meta_polyfill_types

Conversation

@dsherret

Copy link
Copy Markdown
Collaborator

@types/node (>=22.16.3) declares ImportMeta.resolve, which merges with the polyfill's own declaration into an overload set. That provides no contextual type for the assigned function's parameters, so parentURL was inferred as unknown and failed to type check when passed to createRequire:

src/_dnt.polyfills.ts:195:35 - error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'string | URL'.

This only surfaced when the dom lib was included, so the regression test builds the import meta polyfill project with lib: ["ES2022", "DOM"] and @types/node@^22.16.3 (it fails without the fix).

Closes #472

`@types/node` (>=22.16.3) declares `ImportMeta.resolve`, which merges with
the polyfill's own declaration into an overload set. That provides no
contextual type for the assigned function's parameters, so `parentURL`
was inferred as `unknown` and failed to type check when passed to
`createRequire`.

Closes denoland#472
@dsherret
dsherret merged commit 6682c4b into denoland:main Jul 26, 2026
5 checks passed
@dsherret
dsherret deleted the fix_import_meta_polyfill_types branch July 26, 2026 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

typecheck for code with import.meta.dirname polyfill doesn't work

1 participant