microsoft / microsoft/TypeScript

Component not always a valid JSX component depending on a generic type

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

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

Domain: JSX/TSX Help Wanted Possible Improvement
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

Bug Report

🔎 Search Terms

jsx react generic valid JSX

🕗 Version & Regression Information
  • This changed between versions 5.0.4 and 5.1.3
⏯ Playground Link

Playground Link

💻 Code
import * as React from "react";

const A = <T extends unknown>({ a }: { a: T }) => (typeof a === "string" ? null : new Error("a must be a string")) as T extends string ? null : Error;

const jsxWithError = <A<string> a="a" />;

const B = A<string>;

const jsxWithoutError = <B a="a" />;

🙁 Actual behavior

Error on A in jsxWithError:

'A' cannot be used as a JSX component.
  Its type '<T extends unknown>({ a }: { a: T; }) => T extends string ? null : Error' is not a valid JSX element type.
    Type '<T extends unknown>({ a }: { a: T; }) => T extends string ? null : Error' is not assignable to type '(props: any, deprecatedLegacyContext?: any) => ReactNode'.
      Type 'Error' is not assignable to type 'ReactNode'.(2786)
🙂 Expected behavior

No error with the generic type provided (as is the case for jsxWithoutError), since we are sure we are using a valid JSX component.

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

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

はじめの一歩

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

調査の方向性

TypeScript 5.0.4 と 5.1.3 でリンクされた Playground の例を再現し、A のジェネリックな JSX 使用と B の特殊化された使用を比較します。診断 2786 を追跡し、明示的な型引数を指定したジェネリック形式が受け入れられる一方で、既存のエラーケースが意味のあるものとして維持されることを確認します。

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

評価

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

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

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