how to specify string with elements in list?
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 15.5k
- Forks
- 1.5k
- Avg merge
- 10d 23h
- Merged PRs (30d)
- 1
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with JSDoc's documentation on type expressions and compare its supported syntax with the string and Array examples in this issue. Confirm whether the requested space-separated string type can be expressed, and document the result or the supported alternative.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100