microsoft / microsoft/TypeScript

Template decorators.

Aperta
#36,448 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Needs Investigation
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

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)

Playground Link:
http://www.typescriptlang.org/play/?experimentalDecorators=true&ts=3.8-Beta#code/JYWwDg9gTgLgBAbzgYQuCA7AphmAaFNSbXZAGwEMBnKuAXzgDMo04AiKLCgYxjYCh+3TFXjD0JGLQC8cbAHc4AZSwwAPKgk4Y5alTUUMATwKGjAPnMAKAJSDGAVwy9gmOABMs3NQAUCS63FibQAuQi1SShpff3M7BH44JLggzG0qADoKd3crVMk7OkEYIzAsOB8WMBlEOAAPMIwHEAAjLCh6OAAyOCtao0bmto6GAB9agC9B1vbOu34AAU9uISjaZDgsOpgcd3WiNNxfKqpzfgT+OiA

Related Issues:

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

Riprodurre l’esempio fornito con tsc usando --experimentalDecorators e --strict, quindi confrontarlo con il TypeScript Playground collegato usando la 3.8 beta. Iniziare dal controllo dei tipi dei decorator e dal generico ComponentClass nell’esempio. Il lavoro è completato quando si è determinato se la diagnostica 2345 segnalata è errata per il caso delle props union e si è convalidato il comportamento previsto.

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

Valutazione

Stack tecnologico
react, typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
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.