microsoft / microsoft/TypeScript
Template decorators.
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
TypeScript Version: 3.7.5
Search Terms: Decorators, Templates
I know decorators a experimental feature, so this issue is just to push it closer to production ready status.
Notice, I tried typescript version 3.8 beta in the playground.
For local check with tsc only two following flags are essential: "--experimentalDecorators --strict".
It seems like typescript cant pass complex props type. Instead of passing A | B, it just pass A. Using a more simple type A will not produce any errors.
Code
import { Component, ComponentClass } from "react"
const components = new Set<ComponentClass<any, any>>()
function dec<P, S>(component: ComponentClass<P, S>)
{
components.add(component)
}
type Props = { x: number } & ( { y: number } | { z: number } )
@dec
class C extends Component<Props>
{
}
Expected behavior:
Everything works.
Actual behavior:
Following error:
Argument of type 'typeof C' is not assignable to parameter of type 'ComponentClass<{ x: number; } & { y: number; }, {}>'.
Construct signature return types 'C' and 'Component<{ x: number; } & { y: number; }, {}, any>' are incompatible.
The types of 'props' are incompatible between these types.
Type '(Readonly<{ x: number; } & { y: number; }> & Readonly<{ children?: ReactNode; }>) | (Readonly<{ x: number; } & { z: number; }> & Readonly<{ children?: ReactNode; }>)' is not assignable to type 'Readonly<{ x: number; } & { y: number; }> & Readonly<{ children?: ReactNode; }>'.
Type 'Readonly<{ x: number; } & { z: number; }> & Readonly<{ children?: ReactNode; }>' is not assignable to type 'Readonly<{ x: number; } & { y: number; }> & Readonly<{ children?: ReactNode; }>'.
Property 'y' is missing in type 'Readonly<{ x: number; } & { z: number; }> & Readonly<{ children?: ReactNode; }>' but required in type 'Readonly<{ x: number; } & { y: number; }>'.(2345)
Related Issues:
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Das bereitgestellte Beispiel mit tsc unter Verwendung von --experimentalDecorators und --strict reproduzieren und es anschließend mit dem verlinkten TypeScript Playground unter Verwendung der 3.8 beta vergleichen. Mit der Typprüfung von Decorators und dem ComponentClass-Generic im Beispiel beginnen. Als erledigt gilt die Feststellung, ob die gemeldete 2345-Diagnose für den Fall von Union-Props inkorrekt ist, sowie die Validierung des erwarteten Verhaltens.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- react, typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100