microsoft / microsoft/TypeScript

Simplify error messages against intersections of weak types

Offen
#24,146 2 Kommentare 6 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Domain: Error Messages Experience Enhancement Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der JSX-Reproduktion im Issue und verfolge die Typbeziehungsprüfungen für ein Intersection-Ziel mit schwachen Typen. Vergleiche die aktuelle Diagnose mit dem vorgeschlagenen Vergleich, der schwache Typen entfernt; abgeschlossen ist es, wenn der JSX-Fehler vereinfacht wird, ohne das Beziehungsergebnis zu ändern, während weiterhin breitere betroffene Fälle abgedeckt bleiben.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
react, typescript
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.