jsdoc / jsdoc/jsdoc

how to specify string with elements in list?

Open
#2,122 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.