microsoft / microsoft/TypeScript

Type error not indicated when spreading into a JSX component whose props type is defined as interface

Aperta
#43,760 11 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: JSX/TSX
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Bug Report

🔎 Search Terms

react, component props, interface type, spread

🕗 Version & Regression Information

Bug present in 3.3.3 (oldest version available on Playground), as well as Nightly.

⏯ Playground Link

Playground link with relevant code

💻 Code
import * as React from 'react'

// Change interface to a type declaration and the bug disappears.
interface Props {}
// type Props = {}

// Change 'Props' => '{}' (ie. inline the type) and the bug disappears.
function Component(_: Props) { 
    return <div>C2</div>
}

export function Bug() {
    const props = { opt: "1" } as const

    // Should be a type error, since Component doesn't accept 'opt' prop
    return <Component {...props} />
}
🙁 Actual behavior

No error is indicated.

Error is indicated correctly when interface is changed to a type declaration, or the type is inlined.

🙂 Expected behavior

TypeScript should indicate a type error since Component doesn't accept the 'opt' prop.

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 la riproduzione collegata in TypeScript Playground e confronta il controllo dello spread JSX quando Props è un’interface, un type alias o un inline type. Traccia il percorso del controllo dei tipi per la chiamata a Component e verifica la correzione ripristinando l’errore previsto per l’opt prop aggiuntivo, preservando al contempo gli altri casi.

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à
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.