Skip to content
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

Fail when JSX.IntrinsicElements is an intersection type #13345

Closed
Knagis opened this issue Jan 7, 2017 · 6 comments
Closed

Fail when JSX.IntrinsicElements is an intersection type #13345

Knagis opened this issue Jan 7, 2017 · 6 comments
Labels
Bug A bug in TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter
Milestone

Comments

@Knagis
Copy link
Contributor

Knagis commented Jan 7, 2017

TypeScript Version: 2.1.4, 2.2.1, 3.6.3, 4.0.3

The compiler does not support JSX.IntrinsicElements that are intersections. It even fails with an exception instead of an error message.

The reason why I think I require this behavior is that I want the IntrinsicElements to be something like:
{ [P in keyof HTMLElementTagNameMap]: Partial<HTMLElementTagNameMap[P]> } & { [P: string]: Partial<HTMLElement> }

Code

intrinsic.jsx.d.ts

declare namespace JSX {
    // change the alias to use the different versions
    type IntrinsicElements = IntrinsicElements4;

    // works
    type IntrinsicElements1 = {
        a: Partial<HTMLAnchorElement>;
    }

    // works
    type IntrinsicElements2 = {
        [P: string]: Partial<HTMLElement>;
    }

    // works
    type IntrinsicElements3 = {
        a: Partial<HTMLAnchorElement>;
        [P: string]: Partial<HTMLElement>;
    }

    // does not work
    type IntrinsicElements4 = IntrinsicElements1 & IntrinsicElements2;

}

intrinsic.tsx

/// <reference path="intrinsic.jsx.d.ts" />
function jsxCreate() {}

let a = <a href="about:blank">foo</a>;
let b = <foo>bar</foo>;

tsconfig.json

{
    "compilerOptions": {
        "jsx": "react",
        "jsxFactory": "jsxCreate"
    },
    "files": ["intrinsic.tsx"]
}

Expected behavior:

IntrinsicElements4 variation should work the same as IntrinsicElements3 which is semantically the same.

Actual behavior:

The code does not compile, the compiler fails with an exception:

npm\node_modules\typescript\lib\tsc.js:49700
                throw e;
                ^

TypeError: Cannot read property 'members' of undefined
    at getIndexSymbol (npm\node_modules\typescript\lib\tsc.js:23635:26)
    at getIndexDeclarationOfSymbol (npm\node_modules\typescript\lib\tsc.js:23639:31)
    at getIndexInfoOfSymbol (npm\node_modules\typescript\lib\tsc.js:23658:31)
    at getJsxElementAttributesType (npm\node_modules\typescript\lib\tsc.js:28965:56)
    at checkJsxOpeningLikeElement (npm\node_modules\typescript\lib\tsc.js:29015:40)
    at checkJsxElement (npm\node_modules\typescript\lib\tsc.js:28708:13)
    at checkExpressionWorker (npm\node_modules\typescript\lib\tsc.js:31266:28)
    at checkExpression (npm\node_modules\typescript\lib\tsc.js:31182:42)
    at checkExpressionCached (npm\node_modules\typescript\lib\tsc.js:31105:38)
    at checkDeclarationInitializer (npm\node_modules\typescript\lib\tsc.js:31115:24)
@Knagis
Copy link
Contributor Author

Knagis commented Feb 10, 2017

Is there any update on this issue?

@Knagis
Copy link
Contributor Author

Knagis commented Feb 24, 2017

This issue is still present in 2.2.1 - the compiler still crashes with an unhandled exception.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label May 24, 2017
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels Sep 19, 2019
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Sep 19, 2019
@RyanCavanaugh RyanCavanaugh added the Domain: JSX/TSX Relates to the JSX parser and emitter label Sep 19, 2019
@Knagis
Copy link
Contributor Author

Knagis commented Sep 25, 2019

This is still actual in 3.6.3.

@Knagis
Copy link
Contributor Author

Knagis commented Oct 25, 2020

Still actual in 4.0.3 though the message changed a bit

Cannot read property 'flags' of undefined

@Knagis
Copy link
Contributor Author

Knagis commented Oct 25, 2020

Full stack on 4.0.3

node_modules\typescript\lib\tsc.js:84774
                throw e;
                ^

TypeError: Cannot read property 'flags' of undefined
    at tryGetDeclaredTypeOfSymbol (node_modules\typescript\lib\tsc.js:41525:24)
    at getDeclaredTypeOfSymbol (node_modules\typescript\lib\tsc.js:41522:20)
    at getIntrinsicAttributesTypeFromJsxOpeningLikeElement (node_modules\typescript\lib\tsc.js:53880:44)
    at resolveJsxOpeningLikeElement (bug\node_modules\typescript\lib\tsc.js:55928:30)
    at resolveSignature (node_modules\typescript\lib\tsc.js:55967:28)
    at getResolvedSignature (node_modules\typescript\lib\tsc.js:55978:26)
    at checkJsxOpeningLikeElementOrOpeningFragment (node_modules\typescript\lib\tsc.js:53938:27)
    at checkJsxElementDeferred (node_modules\typescript\lib\tsc.js:53562:13)
    at checkDeferredNode (node_modules\typescript\lib\tsc.js:62644:21)
    at Map.forEach **(<anonymous>)**

@Knagis
Copy link
Contributor Author

Knagis commented Jan 12, 2023

Compiler no longer crashes on this example, starting from version 4.3. Seems the issue has been fixed.

@Knagis Knagis closed this as completed Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter
Projects
None yet
Development

No branches or pull requests

2 participants