Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefinitelyTyped (@types/) are not automatically added to package.json from esm.sh #297

Open
LiamAttClarke opened this issue May 20, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@LiamAttClarke
Copy link

LiamAttClarke commented May 20, 2023

Background:

Deno supports automatically resolving type declarations for an external package when the server returns the X-Typescript-Types header.

Example:

GET https://esm.sh/svg-path-parser@1.1.0 >

X-Typescript-Types: https://esm.sh/v122/@types/svg-path-parser@~1.1/index.d.ts

Issue

Type checks fail when declarations are externally sourced from DefinitelyTyped or other.

Example error:

Could not find a declaration file for module 'svg-path-parser'. 'C:/Users/liama/Projects/Personal/svg-plotter/npm/node_modules/svg-path-parser/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/svg-path-parser` if it exists or add a new declaration (.d.ts) file containing `declare module 'svg-path-parser';

Generated package.json:

{
  ...
  "dependencies": {
    "svg-path-parser": "1.1.0",
  },
  "devDependencies": {}
}

Expected Behaviour

dnt should match the behaviour of deno with regards to type declaration resolution. If a referenced package URL responds with an external URL for type declarations, they should be included alongside the dependency list or statically downloaded alongside the source files.

@LiamAttClarke
Copy link
Author

For now, the solution is to manually include these typings like so:

/// <reference types="https://esm.sh/v122/@types/svg-path-parser@1.1.3/index.d.ts" />

@dsherret dsherret changed the title DefinitelyTyped (@types/) are not automatically added to package.json DefinitelyTyped (@types/) are not automatically added to package.json from esm.sh May 23, 2023
@dsherret dsherret added the enhancement New feature or request label May 23, 2023
@dsherret
Copy link
Member

dsherret commented May 23, 2023

This would be nice.

Note that you can add dev dependencies in the build script:

await build({
  // ...etc..
  package: {
    // ...etc...
    devDependencies: {
      "@types/svg-path-parser": "^1.1"
    },
  },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants