Skip to content

feat: add the types package of a mapped dependency to the dev dependencies - #509

Merged
dsherret merged 5 commits into
denoland:mainfrom
dsherret:feat_types_dependencies
Jul 27, 2026
Merged

feat: add the types package of a mapped dependency to the dev dependencies#509
dsherret merged 5 commits into
denoland:mainfrom
dsherret:feat_types_dependencies

Conversation

@dsherret

Copy link
Copy Markdown
Collaborator

Closes #297
Closes #343

When a remote module is mapped to an npm package, the declaration files that the cdn specifies for it were dropped, so the output failed to type check:

import { parseSVG } from "https://esm.sh/svg-path-parser@1.1.0";
error TS7016: Could not find a declaration file for module 'svg-path-parser'.
  Try `npm i --save-dev @types/svg-path-parser` if it exists...

esm.sh points at the declarations with an X-TypeScript-Types header (https://esm.sh/@types/svg-path-parser@~1.1.6/index.d.ts), so now the package providing them is added to the dev dependencies:

{
  "dependencies": {
    "svg-path-parser": "1.1.0"
  },
  "devDependencies": {
    "@types/svg-path-parser": "~1.1.6"
  }
}

The same applies to a declaration file specified with @deno-types, and the file is no longer emitted into the output when a package provides it.

Details:

  • A mapped module isn't in the module graph (a dummy is substituted so it isn't downloaded), so its types header is resolved by fetching it separately. Only modules that the esm.sh and skypack mappers mapped are fetched, so a module the user mapped themselves is still never downloaded. A fetch failure warns and continues rather than failing the build.
  • A declaration file that a module imports directly stays in the output.
  • The readme documents moving the types package to the dependencies when it shows up in your package's public api.

Verified against the reproductions in both issues: https://esm.sh/svg-path-parser@1.1.0 now type checks, and the react example in #343 emits setIsEnabled: React.Dispatch<React.SetStateAction<boolean>> instead of any.

dsherret added 5 commits July 26, 2026 19:11
…ncies

When a remote module is mapped to an npm package, the declaration files
the cdn specifies for it (ex. via an `X-TypeScript-Types` header on
esm.sh) were dropped, so the output failed to type check with
"Could not find a declaration file for module".

Now the npm package providing those declarations is added to the dev
dependencies of the output package.json.

Closes denoland#297
Closes denoland#343
- keep a declaration file in the output when a module imports it directly
- only fetch the modules a cdn mapper mapped, so the modules the user
  mapped themselves are still never downloaded
- resolve the types header relative to the module's final url
- warn when the type declarations of a mapped module can't be resolved
- ignore skypack internal urls, which have a build hash for a version
- match declaration files with a query string or other extensions
@dsherret
dsherret merged commit a59df0a into denoland:main Jul 27, 2026
5 checks passed
@dsherret
dsherret deleted the feat_types_dependencies branch July 27, 2026 00:29
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.

Types not being inferred DefinitelyTyped (@types/) are not automatically added to package.json from esm.sh

1 participant