microsoft / microsoft/TypeScript

Display default values for property types.

Open
#61,045 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

🔎 Search Terms
  • jsdoc property and default tooltip
  • jsdoc declare default values on object properties
  • use jsdoc property with default
🕗 Version & Regression Information

Unsure if it's always been this way.

⏯ Playground Link

https://www.typescriptlang.org/play/?filetype=js#code/LAKFHoCpNACTYAEAuBPADgUwCaYGawDeA9gEYBWmAxsgL6wAKATsegM5wKLotZNpEA5GwC2g2AB9YgkdnFTBAGwDmg+gG1mrNgDo2ASwBemALwy5AXVgAhAK7JkxAHawDxnZyQ9WmfqiJsyEz6TsoaWuw6igCGpJiKVnYOzrAxcYoeIPDgoBDQnohMmMi2TE5sRBFstAW4eNG2ishErkaYAFzSsoIANKmx8Z22TnUhOLA1WZA5IHjDNPopysVVABQAlERwsDtFJWVEk5OgisUtbpiwJl1yfWnxE1ewy8hr66BAA

💻 Code
/**
 * @typedef {object} Props
 * @property {'sm' | 'md' | 'lg'} [Props.size='md'] Button size.
 * @property {string} [Props.label] Button label.
 */

/**
 * @returns {Props}
 * @default { size: 'md', label: undefined }
 */
function getProps() {
    return {}
}

let { size = 'md', label } = getProps()
🙁 Actual behavior

Tooltip when hovering size destructured property:

let size: "sm" | "md" | "lg"
Button size.
🙂 Expected behavior

Tooltip when hovering size destructured property:

let size: "sm" | "md" | "lg"
Button size.
---
@default 'md'
Additional information about the issue

Potentially relates to https://github.com/microsoft/TypeScript/issues/24746

When defining object property types using JSDoc default value notation, such as @property {'sm' | 'md' | 'lg'} [Props.size='md'], I'd like to see tooltip details about the default value. I assume the only way to denote default values with @property is to use [key=value] notation since @default cannot be inlined.

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 the linked TypeScript Playground and reproduce the JSDoc @property default-value case, then compare it with the related issue 24746. Trace how the destructured size tooltip is produced and make the completed behavior display the documented default value, such as @default 'md'.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers, developer-experience
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.