Skip to content

Commit 382f0c3

Browse files
authored
fix: crashes when JSX.IntrinsicClassAttributes is an alias type close microsoftGH-50254 (microsoft#50257)
1 parent 3c3909b commit 382f0c3

File tree

6 files changed

+152
-6
lines changed

6 files changed

+152
-6
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27612,12 +27612,16 @@ namespace ts {
2761227612
if (!isErrorType(intrinsicClassAttribs)) {
2761327613
const typeParams = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(intrinsicClassAttribs.symbol);
2761427614
const hostClassType = getReturnTypeOfSignature(sig);
27615-
apparentAttributesType = intersectTypes(
27616-
typeParams
27617-
? createTypeReference(intrinsicClassAttribs as GenericType, fillMissingTypeArguments([hostClassType], typeParams, getMinTypeArgumentCount(typeParams), isInJSFile(context)))
27618-
: intrinsicClassAttribs,
27619-
apparentAttributesType
27620-
);
27615+
let libraryManagedAttributeType: Type | undefined;
27616+
if (typeParams && typeParams.length === 1) {
27617+
const inferredArgs = fillMissingTypeArguments([hostClassType], typeParams, getMinTypeArgumentCount(typeParams), isInJSFile(context));
27618+
libraryManagedAttributeType = instantiateType(intrinsicClassAttribs, createTypeMapper(typeParams, inferredArgs));
27619+
}
27620+
else if (typeParams) libraryManagedAttributeType = undefined;
27621+
else libraryManagedAttributeType = intrinsicClassAttribs;
27622+
if (libraryManagedAttributeType) {
27623+
apparentAttributesType = intersectTypes(libraryManagedAttributeType, apparentAttributesType);
27624+
}
2762127625
}
2762227626

2762327627
const intrinsicAttribs = getJsxType(JsxNames.IntrinsicAttributes, context);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
tests/cases/compiler/file.tsx(2,19): error TS2741: Property 'ref' is missing in type '{}' but required in type 'IntrinsicClassAttributesAlias<T>'.
2+
3+
4+
==== tests/cases/compiler/file.tsx (1 errors) ====
5+
class App {}
6+
export const a = <App></App>;
7+
~~~
8+
!!! error TS2741: Property 'ref' is missing in type '{}' but required in type 'IntrinsicClassAttributesAlias<T>'.
9+
!!! related TS2728 /.src/tests/cases/compiler/node_modules/@types/react/index.d.ts:2:5: 'ref' is declared here.
10+
==== tests/cases/compiler/node_modules/@types/react/package.json (0 errors) ====
11+
{
12+
"name": "@types/react",
13+
"version": "0.0.1",
14+
"main": "",
15+
"types": "index.d.ts",
16+
}
17+
==== tests/cases/compiler/node_modules/@types/react/index.d.ts (0 errors) ====
18+
interface IntrinsicClassAttributesAlias<T> {
19+
ref: T
20+
}
21+
declare namespace JSX {
22+
type IntrinsicClassAttributes<T> = IntrinsicClassAttributesAlias<T>
23+
}
24+
==== tests/cases/compiler/node_modules/@types/react/jsx-runtime.d.ts (0 errors) ====
25+
import './';
26+
==== tests/cases/compiler/node_modules/@types/react/jsx-dev-runtime.d.ts (0 errors) ====
27+
import './';
28+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//// [tests/cases/compiler/jsxClassAttributeResolution.tsx] ////
2+
3+
//// [file.tsx]
4+
class App {}
5+
export const a = <App></App>;
6+
//// [package.json]
7+
{
8+
"name": "@types/react",
9+
"version": "0.0.1",
10+
"main": "",
11+
"types": "index.d.ts",
12+
}
13+
//// [index.d.ts]
14+
interface IntrinsicClassAttributesAlias<T> {
15+
ref: T
16+
}
17+
declare namespace JSX {
18+
type IntrinsicClassAttributes<T> = IntrinsicClassAttributesAlias<T>
19+
}
20+
//// [jsx-runtime.d.ts]
21+
import './';
22+
//// [jsx-dev-runtime.d.ts]
23+
import './';
24+
25+
26+
//// [file.js]
27+
"use strict";
28+
Object.defineProperty(exports, "__esModule", { value: true });
29+
exports.a = void 0;
30+
const jsx_runtime_1 = require("react/jsx-runtime");
31+
class App {
32+
}
33+
exports.a = (0, jsx_runtime_1.jsx)(App, {});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
=== tests/cases/compiler/file.tsx ===
2+
class App {}
3+
>App : Symbol(App, Decl(file.tsx, 0, 0))
4+
5+
export const a = <App></App>;
6+
>a : Symbol(a, Decl(file.tsx, 1, 12))
7+
>App : Symbol(App, Decl(file.tsx, 0, 0))
8+
>App : Symbol(App, Decl(file.tsx, 0, 0))
9+
10+
=== tests/cases/compiler/node_modules/@types/react/index.d.ts ===
11+
interface IntrinsicClassAttributesAlias<T> {
12+
>IntrinsicClassAttributesAlias : Symbol(IntrinsicClassAttributesAlias, Decl(index.d.ts, 0, 0))
13+
>T : Symbol(T, Decl(index.d.ts, 0, 40))
14+
15+
ref: T
16+
>ref : Symbol(IntrinsicClassAttributesAlias.ref, Decl(index.d.ts, 0, 44))
17+
>T : Symbol(T, Decl(index.d.ts, 0, 40))
18+
}
19+
declare namespace JSX {
20+
>JSX : Symbol(JSX, Decl(index.d.ts, 2, 1))
21+
22+
type IntrinsicClassAttributes<T> = IntrinsicClassAttributesAlias<T>
23+
>IntrinsicClassAttributes : Symbol(IntrinsicClassAttributes, Decl(index.d.ts, 3, 23))
24+
>T : Symbol(T, Decl(index.d.ts, 4, 34))
25+
>IntrinsicClassAttributesAlias : Symbol(IntrinsicClassAttributesAlias, Decl(index.d.ts, 0, 0))
26+
>T : Symbol(T, Decl(index.d.ts, 4, 34))
27+
}
28+
=== tests/cases/compiler/node_modules/@types/react/jsx-runtime.d.ts ===
29+
import './';
30+
No type information for this code.=== tests/cases/compiler/node_modules/@types/react/jsx-dev-runtime.d.ts ===
31+
import './';
32+
No type information for this code.
33+
No type information for this code.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=== tests/cases/compiler/file.tsx ===
2+
class App {}
3+
>App : App
4+
5+
export const a = <App></App>;
6+
>a : any
7+
><App></App> : any
8+
>App : typeof App
9+
>App : typeof App
10+
11+
=== tests/cases/compiler/node_modules/@types/react/index.d.ts ===
12+
interface IntrinsicClassAttributesAlias<T> {
13+
ref: T
14+
>ref : T
15+
}
16+
declare namespace JSX {
17+
type IntrinsicClassAttributes<T> = IntrinsicClassAttributesAlias<T>
18+
>IntrinsicClassAttributes : IntrinsicClassAttributes<T>
19+
}
20+
=== tests/cases/compiler/node_modules/@types/react/jsx-runtime.d.ts ===
21+
import './';
22+
No type information for this code.=== tests/cases/compiler/node_modules/@types/react/jsx-dev-runtime.d.ts ===
23+
import './';
24+
No type information for this code.
25+
No type information for this code.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// @jsx: react-jsx
2+
// @module: nodenext
3+
// @filename: file.tsx
4+
class App {}
5+
export const a = <App></App>;
6+
// @filename: node_modules/@types/react/package.json
7+
{
8+
"name": "@types/react",
9+
"version": "0.0.1",
10+
"main": "",
11+
"types": "index.d.ts",
12+
}
13+
// @filename: node_modules/@types/react/index.d.ts
14+
interface IntrinsicClassAttributesAlias<T> {
15+
ref: T
16+
}
17+
declare namespace JSX {
18+
type IntrinsicClassAttributes<T> = IntrinsicClassAttributesAlias<T>
19+
}
20+
// @filename: node_modules/@types/react/jsx-runtime.d.ts
21+
import './';
22+
// @filename: node_modules/@types/react/jsx-dev-runtime.d.ts
23+
import './';

0 commit comments

Comments
 (0)