Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Feature: Option to remove `| undefined` from optional prop types

Chiusa
#1,134 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
58/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Inizia individuando il punto di ingresso del parser TypeScript e la gestione delle sue opzioni; nell’issue non sono indicati né un file né un test. Confronta l’opzione richiesta con il precedente lavoro collegato di react-docgen-typescript, quindi verifica che il parsing abilitato rimuova | undefined dai tipi delle prop opzionali, preservando il tipo significativo invece di segnalare una union.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem

When using TypeScript's explicit optional property pattern (prop?: Type | undefined), react-docgen displays the type as union instead of showing the actual type.

This pattern is common in codebases using exactOptionalPropertyTypes: true in tsconfig, which requires explicit | undefined for optional properties.

Example
interface ButtonProps {
  onClick?: ((event: MouseEvent) => void) | undefined
  variant?: 'primary' | 'secondary' | undefined
  icon?: ReactNode | undefined
}

In Storybook's props table (using react-docgen), these all display as "union" instead of:

  • (event: MouseEvent) => void
  • 'primary' | 'secondary'
  • ReactNode

Requested Feature

Add a parser option similar to react-docgen-typescript's shouldRemoveUndefinedFromOptional:

{
  shouldRemoveUndefinedFromOptional: true
}

When enabled, this would:

  1. Detect optional properties (those ending with ?)
  2. Strip | undefined from their type representation
  3. Display the actual meaningful type instead of "union"

Prior Art

react-docgen-typescript has this feature via the shouldRemoveUndefinedFromOptional option:
https://github.com/styleguidist/react-docgen-typescript#parseroptions

Workaround

Currently, Storybook users must manually specify table.type.summary for every affected prop:

argTypes: {
  onClick: {
    table: { type: { summary: '(event: MouseEvent) => void' } }
  }
}

This is tedious and error-prone for large component libraries.

Environment

  • react-docgen: latest
  • TypeScript: 7.x with exactOptionalPropertyTypes: true
  • Storybook: 10.x using reactDocgen: 'react-docgen'
Lingua principale
TypeScript
Stelle
3.8k
Fork
316
Merge medio
2h 29m
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di reactjs/react-docgen

Tutte le issue di reactjs/react-docgen

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.