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

Missing type declarations #96

Open
dominik-korsa opened this issue Nov 8, 2020 · 6 comments
Open

Missing type declarations #96

dominik-korsa opened this issue Nov 8, 2020 · 6 comments

Comments

@dominik-korsa
Copy link

Hi, my project uses TypeScript, but after importing this package I get the following error:
image
I can see that there are no .d.ts files in the build folder of the published package, even though the package is written in TypeScript. I haven´t been able to compile the code on my machine, so I cannot investigate this further.

Can you enable building the declarations?

@dominik-korsa
Copy link
Author

I've managed to build the package, the problem was the script: "prepare": "npm run compile", which ran before installing packages, which were required to compile. I think this should be replaced with prepublishOnly.

Anyways, it appears that the definition files get build, but are excluded in the package.json.

"files": [
  "build",
  "index.mjs",
  "!*.d.ts"
],

Is there a reason for doing that?

@bcoe bcoe added the question label Nov 8, 2020
@bcoe
Copy link
Member

bcoe commented Nov 17, 2020

Is there a reason for doing that?

We've been choosing to not publish the types used in yargs' on modules, as it interferes with the types published on DefinitelyTyped -- this decision was mostly motivated by yargs itself, as the @types/yargs module has millions of users.

@kmturley
Copy link

Can you include documentation for use with TypeScript? seems like an incredibly common use-case

@tim-kernegger
Copy link

Changing import statement to require statement fixed it for me
import cliui from 'cliui' to const cliui = require('cliui')

@shadowspawn
Copy link
Member

DefinitelyTyped does not have types for cliui, so it may be fine to include the generated type definitions for direct consumers of this package? There are DefinitelyTyped types for @types/yargs and @types/yargs-parser, but they do not appear to overlap with cliui.

To be clear, the main risk with publishing types in this package is breaking consumers of yargs, which is the biggest dependent on this package. So any insights on that risk are welcome.

@isaacs
Copy link

isaacs commented Apr 28, 2023

In my experience, the only correct way to move to TS from a DT-covered package is semver-major and delete the types from DT. Anything else is asking for headaches. DT is a decent stopgap for JS modules to allow them to be used within TS programs, but once it's written in TS, it's just unnecessary complexity and invariably falls out of sync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants