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

how to specify string with elements in list? #2122

Open
imacks opened this issue Jul 31, 2024 · 1 comment
Open

how to specify string with elements in list? #2122

imacks opened this issue Jul 31, 2024 · 1 comment

Comments

@imacks
Copy link

imacks commented Jul 31, 2024

I know I can constrain a parameter to one of items in a list:

/** @typedef {'a'|'b'|'c'} Alphabet */
/** @param {Alphabet} s */
function write(s) {
  // s will be one of 'a', 'b', or 'c'
}
write('a') // works
write('z') // fails

But what if it's a combination of items in list that is also a string?

write('a b') // works
write('c') // works
write('a z') // fails

I can constrain the input type to Array.<Alphabet> but I do need it to be a string. Help appreciated.

@Mikolaitiene

This comment was marked as spam.

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

2 participants