Skip to content

JSX.ElementType from #51328 doesn't instantiate defaulted type parameters correctly #53939

Closed
@sandersn

Description

@sandersn

In DT, preact dependents like preact-i18n have failures in their tests when they should not:

preact-i18n-tests.tsx:26:13 - error TS2786: 'span' cannot be used as a JSX component.
  Its type '"span"' is not a valid JSX element type.

26     return <span>{test}</span>;

preact's ElementType looks like this:

	export type ElementType<P = any> =
		| {
				[K in keyof IntrinsicElements]: P extends IntrinsicElements[K]
					? K
					: never;
		  }[keyof IntrinsicElements]
		| ComponentType<P>;

Replacing P with any and deleting the type parameter fixes the problem:

	export type ElementType =
		| {
				[K in keyof IntrinsicElements]: any extends IntrinsicElements[K]
					? K
					: never;
		  }[keyof IntrinsicElements]
		| ComponentType<any>;

Broken by #51328. Looks like almost the right test case was added to catch this, but not quite.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueRecent RegressionThis is a new regression just found in the last major/minor version of TypeScript.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions