microsoft / microsoft/TypeScript
Optional arguments in JSDoc types may be moved to TypeScript types quickfix
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.4.3
80004jsdoc quickfix optional
Code
With Closure Compiler, you mark a function parameter optional by adding an = after its type (reference):
/**
* @param a {string} Base string.
* @param b {string=} Optional string to add
* @return {string}
*/
function foo(a, b) {
if (b) return a + b;
return a;
}
TypeScript offers a quickfix to convert these jsdoc annotations to TypeScript types:

Expected behavior:
The b parameter should be optional:
/**
* @param a {string} Base string.
* @param b {string=} Optional string to add
* @return {string}
*/
function foo(a: string, b?: string): string {
if (b) return a + b;
return a;
}
Actual behavior:
The b parameter is required but has type string | optional:
/**
* @param a {string} Base string.
* @param b {string=} Optional string to add
* @return {string}
*/
function foo(a: string, b: string | undefined): string {
if (b) return a + b;
return a;
}
This means that all calls of the function which don't specify b will be flagged as errors.
Playground Link: link, though quickfixes are not available there
Related Issues:
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 by reproducing the JSDoc-to-TypeScript types quickfix with the provided foo function and compare the generated parameter type with the expected optional parameter. Trace the quickfix entry point and add regression coverage showing that calls omitting b are accepted while the generated return type remains string.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100