-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fix crash when the element instance type was undefined #3942
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ddd78fb
Fix crash when the element instance type was undefined
RyanCavanaugh 06f766c
Remove check about ctors returning object types -- it isn't useful
RyanCavanaugh e05a81c
Baseline update
RyanCavanaugh 09aa13f
Merge remote-tracking branch 'upstream/master' into fix3903
RyanCavanaugh 079047c
Simplify code a bit.
RyanCavanaugh 4e3751c
Use Debug.assert instead of Debug.fail; preserve 'any' variants
RyanCavanaugh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
tests/cases/compiler/consumer.tsx(5,17): error TS2604: JSX element type 'BaseComponent' does not have any construct or call signatures. | ||
|
||
|
||
==== tests/cases/compiler/consumer.tsx (1 errors) ==== | ||
/// <reference path="component.d.ts" /> | ||
import BaseComponent = require('BaseComponent'); | ||
class TestComponent extends React.Component<any, {}> { | ||
render() { | ||
return <BaseComponent />; | ||
~~~~~~~~~~~~~ | ||
!!! error TS2604: JSX element type 'BaseComponent' does not have any construct or call signatures. | ||
} | ||
} | ||
|
||
==== tests/cases/compiler/component.d.ts (0 errors) ==== | ||
|
||
declare module JSX { | ||
interface ElementAttributesProperty { props; } | ||
} | ||
declare module React { | ||
class Component<T, U> { } | ||
} | ||
declare module "BaseComponent" { | ||
var base: React.Component<any, {}>; | ||
export = base; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//// [tests/cases/compiler/jsxViaImport.tsx] //// | ||
|
||
//// [component.d.ts] | ||
|
||
declare module JSX { | ||
interface ElementAttributesProperty { props; } | ||
} | ||
declare module React { | ||
class Component<T, U> { } | ||
} | ||
declare module "BaseComponent" { | ||
var base: React.Component<any, {}>; | ||
export = base; | ||
} | ||
|
||
//// [consumer.tsx] | ||
/// <reference path="component.d.ts" /> | ||
import BaseComponent = require('BaseComponent'); | ||
class TestComponent extends React.Component<any, {}> { | ||
render() { | ||
return <BaseComponent />; | ||
} | ||
} | ||
|
||
|
||
//// [consumer.jsx] | ||
var __extends = (this && this.__extends) || function (d, b) { | ||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
/// <reference path="component.d.ts" /> | ||
var BaseComponent = require('BaseComponent'); | ||
var TestComponent = (function (_super) { | ||
__extends(TestComponent, _super); | ||
function TestComponent() { | ||
_super.apply(this, arguments); | ||
} | ||
TestComponent.prototype.render = function () { | ||
return <BaseComponent />; | ||
}; | ||
return TestComponent; | ||
})(React.Component); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
tests/baselines/reference/tsxElementResolution9.errors.txt
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
=== tests/cases/conformance/jsx/tsxElementResolution9.tsx === | ||
declare module JSX { | ||
>JSX : Symbol(JSX, Decl(tsxElementResolution9.tsx, 0, 0)) | ||
|
||
interface Element { } | ||
>Element : Symbol(Element, Decl(tsxElementResolution9.tsx, 0, 20)) | ||
|
||
interface IntrinsicElements { } | ||
>IntrinsicElements : Symbol(IntrinsicElements, Decl(tsxElementResolution9.tsx, 1, 22)) | ||
} | ||
|
||
interface Obj1 { | ||
>Obj1 : Symbol(Obj1, Decl(tsxElementResolution9.tsx, 3, 1), Decl(tsxElementResolution9.tsx, 9, 3)) | ||
|
||
new(n: string): { x: number }; | ||
>n : Symbol(n, Decl(tsxElementResolution9.tsx, 6, 5)) | ||
>x : Symbol(x, Decl(tsxElementResolution9.tsx, 6, 18)) | ||
|
||
new(n: number): { y: string }; | ||
>n : Symbol(n, Decl(tsxElementResolution9.tsx, 7, 5)) | ||
>y : Symbol(y, Decl(tsxElementResolution9.tsx, 7, 18)) | ||
} | ||
var Obj1: Obj1; | ||
>Obj1 : Symbol(Obj1, Decl(tsxElementResolution9.tsx, 3, 1), Decl(tsxElementResolution9.tsx, 9, 3)) | ||
>Obj1 : Symbol(Obj1, Decl(tsxElementResolution9.tsx, 3, 1), Decl(tsxElementResolution9.tsx, 9, 3)) | ||
|
||
<Obj1 />; // Error, return type is not an object type | ||
>Obj1 : Symbol(Obj1, Decl(tsxElementResolution9.tsx, 3, 1), Decl(tsxElementResolution9.tsx, 9, 3)) | ||
|
||
interface Obj2 { | ||
>Obj2 : Symbol(Obj2, Decl(tsxElementResolution9.tsx, 10, 9), Decl(tsxElementResolution9.tsx, 16, 3)) | ||
|
||
(n: string): { x: number }; | ||
>n : Symbol(n, Decl(tsxElementResolution9.tsx, 13, 2)) | ||
>x : Symbol(x, Decl(tsxElementResolution9.tsx, 13, 15)) | ||
|
||
(n: number): { y: string }; | ||
>n : Symbol(n, Decl(tsxElementResolution9.tsx, 14, 2)) | ||
>y : Symbol(y, Decl(tsxElementResolution9.tsx, 14, 15)) | ||
} | ||
var Obj2: Obj2; | ||
>Obj2 : Symbol(Obj2, Decl(tsxElementResolution9.tsx, 10, 9), Decl(tsxElementResolution9.tsx, 16, 3)) | ||
>Obj2 : Symbol(Obj2, Decl(tsxElementResolution9.tsx, 10, 9), Decl(tsxElementResolution9.tsx, 16, 3)) | ||
|
||
<Obj2 />; // Error, return type is not an object type | ||
>Obj2 : Symbol(Obj2, Decl(tsxElementResolution9.tsx, 10, 9), Decl(tsxElementResolution9.tsx, 16, 3)) | ||
|
||
interface Obj3 { | ||
>Obj3 : Symbol(Obj3, Decl(tsxElementResolution9.tsx, 17, 9), Decl(tsxElementResolution9.tsx, 23, 3)) | ||
|
||
(n: string): { x: number }; | ||
>n : Symbol(n, Decl(tsxElementResolution9.tsx, 20, 2)) | ||
>x : Symbol(x, Decl(tsxElementResolution9.tsx, 20, 15)) | ||
|
||
(n: number): { x: number; y: string }; | ||
>n : Symbol(n, Decl(tsxElementResolution9.tsx, 21, 2)) | ||
>x : Symbol(x, Decl(tsxElementResolution9.tsx, 21, 15)) | ||
>y : Symbol(y, Decl(tsxElementResolution9.tsx, 21, 26)) | ||
} | ||
var Obj3: Obj3; | ||
>Obj3 : Symbol(Obj3, Decl(tsxElementResolution9.tsx, 17, 9), Decl(tsxElementResolution9.tsx, 23, 3)) | ||
>Obj3 : Symbol(Obj3, Decl(tsxElementResolution9.tsx, 17, 9), Decl(tsxElementResolution9.tsx, 23, 3)) | ||
|
||
<Obj3 x={42} />; // OK | ||
>Obj3 : Symbol(Obj3, Decl(tsxElementResolution9.tsx, 17, 9), Decl(tsxElementResolution9.tsx, 23, 3)) | ||
>x : Symbol(unknown) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
=== tests/cases/conformance/jsx/tsxElementResolution9.tsx === | ||
declare module JSX { | ||
>JSX : any | ||
|
||
interface Element { } | ||
>Element : Element | ||
|
||
interface IntrinsicElements { } | ||
>IntrinsicElements : IntrinsicElements | ||
} | ||
|
||
interface Obj1 { | ||
>Obj1 : Obj1 | ||
|
||
new(n: string): { x: number }; | ||
>n : string | ||
>x : number | ||
|
||
new(n: number): { y: string }; | ||
>n : number | ||
>y : string | ||
} | ||
var Obj1: Obj1; | ||
>Obj1 : Obj1 | ||
>Obj1 : Obj1 | ||
|
||
<Obj1 />; // Error, return type is not an object type | ||
><Obj1 /> : JSX.Element | ||
>Obj1 : Obj1 | ||
|
||
interface Obj2 { | ||
>Obj2 : Obj2 | ||
|
||
(n: string): { x: number }; | ||
>n : string | ||
>x : number | ||
|
||
(n: number): { y: string }; | ||
>n : number | ||
>y : string | ||
} | ||
var Obj2: Obj2; | ||
>Obj2 : Obj2 | ||
>Obj2 : Obj2 | ||
|
||
<Obj2 />; // Error, return type is not an object type | ||
><Obj2 /> : JSX.Element | ||
>Obj2 : Obj2 | ||
|
||
interface Obj3 { | ||
>Obj3 : Obj3 | ||
|
||
(n: string): { x: number }; | ||
>n : string | ||
>x : number | ||
|
||
(n: number): { x: number; y: string }; | ||
>n : number | ||
>x : number | ||
>y : string | ||
} | ||
var Obj3: Obj3; | ||
>Obj3 : Obj3 | ||
>Obj3 : Obj3 | ||
|
||
<Obj3 x={42} />; // OK | ||
><Obj3 x={42} /> : JSX.Element | ||
>Obj3 : Obj3 | ||
>x : any | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//@jsx: preserve | ||
//@module: commonjs | ||
|
||
//@filename: component.d.ts | ||
declare module JSX { | ||
interface ElementAttributesProperty { props; } | ||
} | ||
declare module React { | ||
class Component<T, U> { } | ||
} | ||
declare module "BaseComponent" { | ||
var base: React.Component<any, {}>; | ||
export = base; | ||
} | ||
|
||
//@filename: consumer.tsx | ||
/// <reference path="component.d.ts" /> | ||
import BaseComponent = require('BaseComponent'); | ||
class TestComponent extends React.Component<any, {}> { | ||
render() { | ||
return <BaseComponent />; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under what situations does
getJsxElementInstanceType
returnundefined
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When type of the specified element has no call or construct signatures
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RyanCavanaugh just tried the solution we discussed in #3960 and it fails to:
So maybe the error is not because of call or construct signature?
https://github.com/s-panferov/ts-jsx-issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RyanCavanaugh output from your branch:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RyanCavanaugh I found a working example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hadn't tested with intersection types before. Updating.