-
Notifications
You must be signed in to change notification settings - Fork 995
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
@types/typescript does not work with import
syntax
#1749
Comments
https://github.com/yargs/yargs#typescript |
This worked with yargs 15.4.2
|
Maintainers are working to convert the entire project to TypeScript: #1586 |
I apologize for the confusion it created having this briefly work in v15. We do not intend to ship TypeScript definitions in yargs or yargs-parser in the near future. Here's a post on the topic.
Basically, we had the choice break TypeScript for 1000s of existing libraries, or ship without types ourselves... I think this is the right call. The other problem with shipping the library itself with the types is that breaking changes to types vs the API surface become indistinguishable. |
I understand that pure javascript libraries can be used in typescript projects (as in they can be imported and used, but not type checked), and I assumed that's how it previously worked. Currently it can't be imported at all.
|
@dalcde the syntax should be: #!/usr/bin/env node
import yargs = require('yargs');
const argv = yargs.options({
a: { type: 'boolean', default: false },
b: { type: 'string', demandOption: true },
c: { type: 'number', alias: 'chill' },
d: { type: 'array' },
e: { type: 'count' },
f: { choices: ['1', '2', '3'] }
}).argv; I believe to match the |
import
syntax
@dalcde I wonder if, now that we support ESM in yargs, there's a way The reason that |
@bcoe you can already We are getting yargs in its EDIT: just to clarify... |
@AviVahl, I wish this was a bit more straightforward for folks ... especially now that the library itself does support ESM. I think there's just room to improve the ESM/TypeScript interop story. |
I get the same error with --esModuleInterop
|
@dalcde could you share a minimal repository that is having this issue? |
The commands at the OP of the issue creates such a repository.
|
Those commands do not include
Works just fine (notice the added |
I can confirm that adding `@types/yargs` solves the problem. `tsc --init` does not.
The issue was that javascript libraries are normally usable with
typescript without typings, and that was the case with yargs prior to
16.0
|
Reproduce by running the following in an empty directory:
We get the error
Reproduced with
yargs 16.0.3
andtsc 4.0.2
.The text was updated successfully, but these errors were encountered: