-
-
Notifications
You must be signed in to change notification settings - Fork 151
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
[TS] Any way to predefine the flags then typecheck them in options? #129
Comments
Why do you need to predefine them? The Meow types are smart enough to use the correct types depending on what you specify in the // @NiGhTTraX |
That's because:
|
@whitetrefoil you don't need to pass a generic type to type Flags = {
foo: number;
}
const cli: { flags: Flags } = meow({
flags: {
foo: { type: 'number' }
}
}); You would get a type error if you tried to use |
@NiGhTTraX That's a nice workaround. I'll use it before I find a better way (if there is). Thanks a lot! |
The solution suggested by @NiGhTTraX sounds like the proper one to me. It's even the one used in Lines 8 to 16 in 629af48
|
Would this not be solved by a very simple export of // file_1.ts
const flags: AnyFlags = {
unicorn: {
type: 'string',
},
};
// file_2.ts
meow(flags); |
Ive tried the approach that was suggested by @NiGhTTraX but i got some errors(see example_type1 photo) |
@techtony92 you can use the type Flags = { foo: string };
const x = meow({
importMeta: import.meta,
flags: {
foo: { type: "number", isRequired: true },
},
}) satisfies { flags: Flags };
// You get type checking here:
// TS1360: Type number is not assignable to type string
// You preserve the meow type here:
console.log(x.help);
// ^? string
console.log(x.flags.foo);
// ^? number |
Currently the type of flags are difficult to predefine, it'll be easier to write the
meow(..., ...)
function then get the returned type.But I'm trying to predefine the flags' type then use it to typecheck the
meow()
function. e.g.:The text was updated successfully, but these errors were encountered: