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
TypeScript examples don't compile #1455
Comments
It is notable that using |
Aha! import * as yargs from 'yargs'; results in proper types working. Is this a code smell or should I just file a pull request on the docs to change them to this syntax? (again, I don't know about the conventions around modules in TS) |
I think it depends on your tsconfig. If you have |
👋 any thoughts on whether we should suggest using |
That is a fantastic question. I think we should probably suggest using esModuleInterop since that results in the code being compliant with the ES modules spec which might imply it's more "best practice" (assuming I read the Stack Overflow answer about this correctly). But I'm not a JavaScript developer and don't know enough about the context here to make that decision. Still I could write up a pull request of this and see what others think. |
perhaps this just means that we should update the docs to call out this configuration. |
Actually, through this, I solved another error! I wasn't able to type I'm typing it like this: interface Arguments {
_: any;
gradlePath: string;
iosPath: string;
bldSettings: string;
}
const argv: Arguments = yargs.options({
bldSettings: { type: "string" },
gradlePath: { type: "string" },
iosPath: { type: "string" }
}).argv; In particular, this was the error
UPDATE:
|
@giacomocerquone in this example, I think this is a different issue; once you get things working, I would happily accept an update to the TypeScript example; I think we should probably avoid |
Ok but why does it disappear when using require instead of import? |
@giacomocerquone I believe |
I have import yargs from 'yargs'
// or
import * as yargs from 'yargs' and ((yargs() as unknown) as Argv<{}>) // Chain your method calls here Not the cleanest syntax but it's a pretty safe coercion and allows type checking to work correctly. |
@Jack-Barry Please have a look at the doc fix in #1513 (not merged yet). You should use |
Hi! I've been converting a project to use Yargs recently and was having some issues with the compiler being dissatisfied with my program, so I tried one of the examples in
docs/typescript.md
to see if I could better understand the issue.Unfortunately, it seems to have the same problem as my code was having:
It appears that the compiler is possibly not seeing whatever object results from
import yargs from 'yargs'
as an instance of Argv, which seems very strange indeed. How should we fix the examples so they compile, or fix the definitions so they work with the examples?Contents of
test.ts
:Versions:
The text was updated successfully, but these errors were encountered: