-
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
Conversation
@@ -7261,7 +7261,7 @@ namespace ts { | |||
if (links.jsxFlags & JsxFlags.ClassElement) { | |||
let elemInstanceType = getJsxElementInstanceType(node); |
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
return undefined
?
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:
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?
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:
➜ 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.
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
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 />;
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.
Conflicts: tests/baselines/reference/tsxElementResolution9.errors.txt
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))); |
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.
You can reduce this lambda
👍 |
Fix crash when the element instance type was undefined
Fixes issue #3903