microsoft / microsoft/TypeScript

Enforce property rules on kebab-cased JSX attributes

Aperta
#55,182 9 commenti 22 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Bug Report

Reference: https://github.com/microsoft/TypeScript/issues/32447

I thought it was a good idea to reopen this given it's been 4 years and TS's features have advanced substantially since that last issue was filed and closed.

Quoting @RyanCavanaugh

This is the intended behavior because of data- and aria- properties. If we ever get regex-based property names, we'll revisit.

Given we now have template literal types - this is probably ripe for revisiting!

🔎 Search Terms

jsx dash property missing error kebab case

🕗 Version & Regression Information
  • This is the behavior in every version I tried
⏯ Playground Link

Playground link with relevant code

💻 Code
type Props = {
  a?: string,
  'some-kebab-property'?: boolean;
} & {
  [k in `data-${string}` | `aria-${string}` | `hello${string}`]?: string
} & {
  [k in 'kebab-case1' | 'kebab-case2']?: string
};
function Component(props: Props) { return null }

function Other() {
  <Component
    a={1} // ✅ expected error
  
    b={1} // ✅ expected error
    
    hello={1} // ✅ expected
    helloThere={1} // ✅ expected
    
    aria-label="" // ✅ valid
    data-foo="" // ✅ valid
  />;

  // ❓ errors on the component, rather than the property
  <Component
    kebab-case1={1}
    kebab-case2={1}
  />;

  // ❓ errors on the component, rather than the property
  <Component
    some-kebab-property={1}
  />;

  <Component
    data-bar={1} // ❌ should error but doesn't
  />;

  <Component
    property-that-definitely-doesnt-exist-yet-ts-does-not-error-on-it={false} // ❌ should error but doesn't
  />;
}
🙁 Actual behavior

This errors on the component, not the property

  <Component
    kebab-case1={1}
    kebab-case2={1}
  />;

  <Component
    some-kebab-property={1}
  />;

These do not error at all

  <Component
    data-bar={1}
  />;

  <Component
    property-that-definitely-doesnt-exist-yet-ts-does-not-error-on-it={false}
  />;
🙂 Expected behavior

This should error on the property - but it errors on the component instead

  <Component
    kebab-case1={1}
    kebab-case2={1}
  />;

  <Component
    some-kebab-property={1}
  />;

Should error because it doesn't match the defined template literal mapped type

  <Component
    data-bar={1}
  />;

Should error because the property doesn't exist

  <Component
    property-that-definitely-doesnt-exist-yet-ts-does-not-error-on-it={false}
  />;

Guida per i contributori

Apri la guida per i contributori

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.

Direzione di ricerca

Inizia con il TypeScript Playground collegato e l'esempio JSX per riprodurre il modo in cui vengono verificati gli attributi in kebab-case. Confronta i diagnostici per le proprietà mappate esplicitamente, data-bar e la proprietà sconosciuta; il lavoro è completo quando gli attributi non validi producono errori a livello di proprietà, mentre gli attributi validi con prefisso data- e aria- continuano a essere accettati.

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

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.