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

Documentation tips for TypeScript #141

Open
shadowspawn opened this issue Aug 11, 2022 · 1 comment
Open

Documentation tips for TypeScript #141

shadowspawn opened this issue Aug 11, 2022 · 1 comment

Comments

@shadowspawn
Copy link
Collaborator

To get the most out of the typings, the input conjuration needs to be static or const in Typescript. We should add a tip in the documentation here and in utils to reduce potential confusion.

// accurate
const results1 = parseArgs({ options: { foo: { type: 'string' }}});

// accurate
const config2 = { options: { foo: { type: 'string' }}} as const;
const results2 = parseArgs(config2);

// error because `type` is typed as string and not `'type'` so TypeScript can not check used correctly
const config3 = { options: { foo: { type: 'string' }}};
const results3 = parseArgs(config3); // error

Related comment:

@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Aug 29, 2022

If I understand correctly, the types for @pkgjs/parseargs will be available as @types/pkgjs__parseargs. I didn't know about this pattern for types for scoped packages, and I think worth putting in a tip about that in the README too.

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

No branches or pull requests

1 participant