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
Allow JS constructor function to return non-void #16196
Conversation
src/compiler/checker.ts
Outdated
@@ -15835,7 +15835,7 @@ namespace ts { | |||
const callSignatures = getSignaturesOfType(expressionType, SignatureKind.Call); | |||
if (callSignatures.length) { | |||
const signature = resolveCall(node, callSignatures, candidatesOutArray); | |||
if (getReturnTypeOfSignature(signature) !== voidType) { | |||
if (!isInJavaScriptFile(signature.declaration) && getReturnTypeOfSignature(signature) !== voidType) { |
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.
should not we check functionSymbol.members
here to make sure the function has a this.prop = ..
somewhere, and avoid something like new getNumber()
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.
Probably, but I need to fix #14056 first to properly resolve the underlying function to get to the symbols. Right now the symbol points to the local var declaration and doesn't have this information.
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.
Can you add some conformance tests for these patterns also the use of @class
This loosens the restriction that a function must return
void
if it is to be used as a constructor when the function is defined in a JavaScript file.Fixes #15959