preactjs / preact-router

:earth_americas: URL router for Preact.
http://npm.im/preact-router
MIT License
1.01k stars 156 forks source link

package.json's exports mapping does not include types field #429

Closed jeffposnick closed 1 year ago

jeffposnick commented 2 years ago

When trying to import the preact-router and preact-router/match modules from inside a project written using TypeScript 4.7+ with moduleResolution: "NodeNext", TypeScript is unable to find the corresponding type definitions.

If I manually modify node_modules/preact-router/package.json to add types fields to the preact-router and preact-router/match exports, then TypeScript will pick up the type definitions:

"exports": {
    ".": {
        "module": "./dist/preact-router.mjs",
        "import": "./dist/preact-router.mjs",
        "require": "./dist/preact-router.js",
        "types": "./index.d.ts"
    },
    "./package.json": "./package.json",
    "./match": {
        "module": "./match/index.mjs",
        "import": "./match/index.mjs",
        "require": "./match/index.js",
        "types": "./match/index.d.ts"
    },
    "./match/package.json": "./match/package.json"
},

Can this module be published with the addition of those types fields in the exports section of package.json? I'm happy to file a PR to add them if that seems reasonable.

See https://github.com/developit/microbundle/issues/990 for a related discussion about documenting this as part of microbundle's TypeScript guidance.