Skip to content

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 6 commits into from
Jul 27, 2015

Conversation

RyanCavanaugh
Copy link
Member

Fixes issue #3903

@@ -7261,7 +7261,7 @@ namespace ts {
if (links.jsxFlags & JsxFlags.ClassElement) {
let elemInstanceType = getJsxElementInstanceType(node);
Copy link
Member

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 return undefined?

Copy link
Member Author

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

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:

import * as React from 'react';

class C extends React.Component<any, any> {
    render() {
        return null
    }
}

type ReactCtor<P, S> = new() => React.Component<P, S> & { render(): React.ReactElement<P> };
let C1: ReactCtor<any, any> = C;
let a = <C1 />;

So maybe the error is not because of call or construct signature?

https://github.com/s-panferov/ts-jsx-issue

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:

➜  ts-jsx-issue git:(master) ✗ ../TypeScript/bin/tsc --target es6 --jsx react issue.tsx
issue.tsx(17,10): error TS2601: The return type of a JSX element constructor must return an object type.

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

interface JsxClass<P, S> extends React.Component<P, S> {
    render(): React.ReactElement<P>
}

interface ReactCtor<P, S> {
    new(props: P): JsxClass<P, S>;
}

let C1: ReactCtor<any, any> = C;
let a = <C1 />;

Copy link
Member Author

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.

@RyanCavanaugh
Copy link
Member Author

Anyone care to take a look? We should get this in for 1.6

@@ -7353,12 +7353,7 @@ namespace ts {
}
}

// Check that the constructor/factory returns an object type
let returnType = getUnionType(signatures.map(s => getReturnTypeOfSignature(s)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can reduce this lambda

@JsonFreeman
Copy link
Contributor

👍

RyanCavanaugh added a commit that referenced this pull request Jul 27, 2015
Fix crash when the element instance type was undefined
@RyanCavanaugh RyanCavanaugh merged commit 0da9b7a into microsoft:master Jul 27, 2015
@RyanCavanaugh RyanCavanaugh deleted the fix3903 branch July 28, 2015 17:02
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants