microsoft / microsoft/TypeScript

Template decorators.

オープン
#36,448 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Needs Investigation
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

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:

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

提供された例を --experimentalDecorators と --strict を使って tsc で再現し、その後、3.8 beta を使ったリンク先の TypeScript Playground と比較する。例における decorator の型チェックと ComponentClass ジェネリックから始める。報告された 2345 診断が union props のケースで誤っているかどうかを判断し、期待される動作を検証できれば完了とする。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
react, typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。