Skip to content

Commit 3b35522

Browse files
authored
Type lookup in getIntrinsicAttributestypeFromJsxOpeningLikeElement should match getIntrinsicTagSymbol (#42819)
1 parent 5c0b839 commit 3b35522

File tree

5 files changed

+132
-2
lines changed

5 files changed

+132
-2
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26059,11 +26059,11 @@ namespace ts {
2605926059
if (!links.resolvedJsxElementAttributesType) {
2606026060
const symbol = getIntrinsicTagSymbol(node);
2606126061
if (links.jsxFlags & JsxFlags.IntrinsicNamedElement) {
26062-
return links.resolvedJsxElementAttributesType = getTypeOfSymbol(symbol);
26062+
return links.resolvedJsxElementAttributesType = getTypeOfSymbol(symbol) || errorType;
2606326063
}
2606426064
else if (links.jsxFlags & JsxFlags.IntrinsicIndexedElement) {
2606526065
return links.resolvedJsxElementAttributesType =
26066-
getIndexTypeOfType(getDeclaredTypeOfSymbol(symbol), IndexKind.String)!;
26066+
getIndexTypeOfType(getJsxType(JsxNames.IntrinsicElements, node), IndexKind.String) || errorType;
2606726067
}
2606826068
else {
2606926069
return links.resolvedJsxElementAttributesType = errorType;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//// [index.tsx]
2+
export class X {
3+
static jsx() {
4+
return document.createElement('p');
5+
}
6+
}
7+
8+
export namespace X {
9+
export namespace JSX {
10+
export type IntrinsicElements = {
11+
[other: string]: any;
12+
};
13+
}
14+
}
15+
16+
function A() {
17+
return (<p>Hello</p>);
18+
}
19+
20+
//// [index.js]
21+
"use strict";
22+
exports.__esModule = true;
23+
exports.X = void 0;
24+
var X = /** @class */ (function () {
25+
function X() {
26+
}
27+
X.jsx = function () {
28+
return document.createElement('p');
29+
};
30+
return X;
31+
}());
32+
exports.X = X;
33+
function A() {
34+
return (X.jsx("p", null, "Hello"));
35+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=== tests/cases/compiler/index.tsx ===
2+
export class X {
3+
>X : Symbol(X, Decl(index.tsx, 0, 0), Decl(index.tsx, 4, 1))
4+
5+
static jsx() {
6+
>jsx : Symbol(X.jsx, Decl(index.tsx, 0, 16))
7+
8+
return document.createElement('p');
9+
>document.createElement : Symbol(Document.createElement, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
10+
>document : Symbol(document, Decl(lib.dom.d.ts, --, --))
11+
>createElement : Symbol(Document.createElement, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
12+
}
13+
}
14+
15+
export namespace X {
16+
>X : Symbol(X, Decl(index.tsx, 0, 0), Decl(index.tsx, 4, 1))
17+
18+
export namespace JSX {
19+
>JSX : Symbol(JSX, Decl(index.tsx, 6, 20))
20+
21+
export type IntrinsicElements = {
22+
>IntrinsicElements : Symbol(IntrinsicElements, Decl(index.tsx, 7, 26))
23+
24+
[other: string]: any;
25+
>other : Symbol(other, Decl(index.tsx, 9, 13))
26+
27+
};
28+
}
29+
}
30+
31+
function A() {
32+
>A : Symbol(A, Decl(index.tsx, 12, 1))
33+
34+
return (<p>Hello</p>);
35+
>p : Symbol(__type, Decl(index.tsx, 8, 39))
36+
>p : Symbol(__type, Decl(index.tsx, 8, 39))
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=== tests/cases/compiler/index.tsx ===
2+
export class X {
3+
>X : X
4+
5+
static jsx() {
6+
>jsx : () => HTMLParagraphElement
7+
8+
return document.createElement('p');
9+
>document.createElement('p') : HTMLParagraphElement
10+
>document.createElement : { <K extends keyof HTMLElementTagNameMap>(tagName: K, options?: ElementCreationOptions): HTMLElementTagNameMap[K]; <K extends keyof HTMLElementDeprecatedTagNameMap>(tagName: K, options?: ElementCreationOptions): HTMLElementDeprecatedTagNameMap[K]; (tagName: string, options?: ElementCreationOptions): HTMLElement; }
11+
>document : Document
12+
>createElement : { <K extends keyof HTMLElementTagNameMap>(tagName: K, options?: ElementCreationOptions): HTMLElementTagNameMap[K]; <K extends keyof HTMLElementDeprecatedTagNameMap>(tagName: K, options?: ElementCreationOptions): HTMLElementDeprecatedTagNameMap[K]; (tagName: string, options?: ElementCreationOptions): HTMLElement; }
13+
>'p' : "p"
14+
}
15+
}
16+
17+
export namespace X {
18+
export namespace JSX {
19+
export type IntrinsicElements = {
20+
>IntrinsicElements : IntrinsicElements
21+
22+
[other: string]: any;
23+
>other : string
24+
25+
};
26+
}
27+
}
28+
29+
function A() {
30+
>A : () => any
31+
32+
return (<p>Hello</p>);
33+
>(<p>Hello</p>) : error
34+
><p>Hello</p> : error
35+
>p : any
36+
>p : any
37+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @jsx: react
2+
// @jsxFactory: X.jsx
3+
// @filename: index.tsx
4+
5+
export class X {
6+
static jsx() {
7+
return document.createElement('p');
8+
}
9+
}
10+
11+
export namespace X {
12+
export namespace JSX {
13+
export type IntrinsicElements = {
14+
[other: string]: any;
15+
};
16+
}
17+
}
18+
19+
function A() {
20+
return (<p>Hello</p>);
21+
}

0 commit comments

Comments
 (0)