Microsoft/TypeScript
GitHub ã§èŠãComponent not always a valid JSX component depending on a generic type
Open
#54,702 opened on 2023幎6æ19æ¥
Domain: JSX/TSXHelp WantedPossible Improvement
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
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
ð» 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.