Skip to content

Type lookup in getIntrinsicAttributestypeFromJsxOpeningLikeElement should match getIntrinsicTagSymbol #42819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25881,11 +25881,11 @@ namespace ts {
if (!links.resolvedJsxElementAttributesType) {
const symbol = getIntrinsicTagSymbol(node);
if (links.jsxFlags & JsxFlags.IntrinsicNamedElement) {
return links.resolvedJsxElementAttributesType = getTypeOfSymbol(symbol);
return links.resolvedJsxElementAttributesType = getTypeOfSymbol(symbol) || errorType;
}
else if (links.jsxFlags & JsxFlags.IntrinsicIndexedElement) {
return links.resolvedJsxElementAttributesType =
getIndexTypeOfType(getDeclaredTypeOfSymbol(symbol), IndexKind.String)!;
getIndexTypeOfType(getJsxType(JsxNames.IntrinsicElements, node), IndexKind.String) || errorType;
}
else {
return links.resolvedJsxElementAttributesType = errorType;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//// [index.tsx]
export class X {
static jsx() {
return document.createElement('p');
}
}

export namespace X {
export namespace JSX {
export type IntrinsicElements = {
[other: string]: any;
};
}
}

function A() {
return (<p>Hello</p>);
}

//// [index.js]
"use strict";
exports.__esModule = true;
exports.X = void 0;
var X = /** @class */ (function () {
function X() {
}
X.jsx = function () {
return document.createElement('p');
};
return X;
}());
exports.X = X;
function A() {
return (X.jsx("p", null, "Hello"));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
=== tests/cases/compiler/index.tsx ===
export class X {
>X : Symbol(X, Decl(index.tsx, 0, 0), Decl(index.tsx, 4, 1))

static jsx() {
>jsx : Symbol(X.jsx, Decl(index.tsx, 0, 16))

return document.createElement('p');
>document.createElement : Symbol(Document.createElement, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
>document : Symbol(document, Decl(lib.dom.d.ts, --, --))
>createElement : Symbol(Document.createElement, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
}
}

export namespace X {
>X : Symbol(X, Decl(index.tsx, 0, 0), Decl(index.tsx, 4, 1))

export namespace JSX {
>JSX : Symbol(JSX, Decl(index.tsx, 6, 20))

export type IntrinsicElements = {
>IntrinsicElements : Symbol(IntrinsicElements, Decl(index.tsx, 7, 26))

[other: string]: any;
>other : Symbol(other, Decl(index.tsx, 9, 13))

};
}
}

function A() {
>A : Symbol(A, Decl(index.tsx, 12, 1))

return (<p>Hello</p>);
>p : Symbol(__type, Decl(index.tsx, 8, 39))
>p : Symbol(__type, Decl(index.tsx, 8, 39))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
=== tests/cases/compiler/index.tsx ===
export class X {
>X : X

static jsx() {
>jsx : () => HTMLParagraphElement

return document.createElement('p');
>document.createElement('p') : HTMLParagraphElement
>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; }
>document : 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; }
>'p' : "p"
}
}

export namespace X {
export namespace JSX {
export type IntrinsicElements = {
>IntrinsicElements : IntrinsicElements

[other: string]: any;
>other : string

};
}
}

function A() {
>A : () => any

return (<p>Hello</p>);
>(<p>Hello</p>) : error
><p>Hello</p> : error
>p : any
>p : any
}
21 changes: 21 additions & 0 deletions tests/cases/compiler/jsxLocalNamespaceIndexSignatureNoCrash.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @jsx: react
// @jsxFactory: X.jsx
// @filename: index.tsx

export class X {
static jsx() {
return document.createElement('p');
}
}

export namespace X {
export namespace JSX {
export type IntrinsicElements = {
[other: string]: any;
};
}
}

function A() {
return (<p>Hello</p>);
}