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

Add choices option #171

Closed
hosseinmd opened this issue Dec 4, 2020 · 6 comments · Fixed by #228
Closed

Add choices option #171

hosseinmd opened this issue Dec 4, 2020 · 6 comments · Fixed by #228

Comments

@hosseinmd
Copy link

I want to define a type like this:

      aFlag: {
        type: "global" | "local",
        default: "global",
      },

How this possible? or if that is not possible. could you implement it?

@sindresorhus
Copy link
Owner

What are you trying to do? First, those type values are not valid, even without the "or". Second, how would it be able to decide which type to use?

@hosseinmd
Copy link
Author

Imagine I have an argument which gets two values "local" or "global".

@sindresorhus
Copy link
Owner

You didn't answer all my questions.

@hosseinmd
Copy link
Author

how would it be able to decide which type to use?

I don't familiar with meow project but on Typescript, we could do it like this:

function example<T>(type: T): T extends ReadonlyArray<infer K> ? K : T {
  return "" as any;
}

example(["foo", "bar"] as const) === "foo";
// example return 'foo' | 'bar

@sindresorhus
Copy link
Owner

Ok, I get it now. The type should still be a string though. What you want is something like .choices() in Yargs: http://yargs.js.org/docs/#choices Basically, specify a list of the possible values to the flag.

That's not supported today, but I'll mark this as a feature request.

@sindresorhus sindresorhus changed the title (Question or feature request) How to define type with or Add choices option Dec 7, 2020
Repository owner deleted a comment from toshihidetagami Dec 10, 2022
@sindresorhus
Copy link
Owner

If anyone wants to work on this, see the initial attempt in #183 (Also make sure you intend to finish it!)

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

Successfully merging a pull request may close this issue.

2 participants