microsoft / microsoft/TypeScript

Simplify error messages against intersections of weak types

Aperta
#24,146 2 commenti 6 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Domain: Error Messages Experience Enhancement Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

I spoke a bit with @sandersn about ways we can tackle the type madness issue (#14662). I noted that JSX scenarios are much more broadly applicable right now and are pretty prevalent given the sorts of type arithmetic we see a lot of in the React community. 😃

Problem: JSX optional attributes make errors too hard to read

interface FooProps {
    name: string;
    age: number;
}

class Foo extends React.Component<FooProps> {
    constructor(props: FooProps) {
        super(props)
    }
    render() {
        const {name, age} = this.props;
        return <div>I'm {name} and am {age} years old</div>;
    }
}

// Type '{ blah: number; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Foo> & Readonly<{ children?: ReactNode; }> & Reado...'.
//   Type '{ blah: number; }' is not assignable to type 'Readonly<FooProps>'.
//     Property 'name' is missing in type '{ blah: number; }'.
<Foo blah={10} />;

Proposal

When doing relation checks against an intersection target, if a check fails, see if relating against the same type with weak types removed would result in the same outcome. If so, use that comparison when elaborating types.

The great part is that this actually solves a broader set of problems than just JSX.

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 JSX nell’issue e segui i controlli delle relazioni tra tipi per una destinazione di intersezione con tipi deboli. Confronta la diagnostica attuale con il confronto proposto che rimuove i tipi deboli; il lavoro è completato quando l’errore JSX viene semplificato senza modificare il risultato della relazione, continuando a coprire i casi interessati più ampi.

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

Valutazione

Stack tecnologico
react, typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.