Skip to content

#27370 breaks narrowing for constructor functions #27550

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

Closed
sandersn opened this issue Oct 4, 2018 · 0 comments · Fixed by #27551
Closed

#27370 breaks narrowing for constructor functions #27550

sandersn opened this issue Oct 4, 2018 · 0 comments · Fixed by #27551
Labels
Bug A bug in TypeScript Domain: JavaScript The issue relates to JavaScript specifically Fixed A PR has been merged for this issue

Comments

@sandersn
Copy link
Member

sandersn commented Oct 4, 2018

Based on code from uglify:

/** @constructor */
function AtTop(val) { this.val = val }
/** @type {*} */
var x = 1;
if (x instanceof AtTop) {
    x.val
}

Expected behavior:

x doesn't narrow inside the if and x: any and x.val: any.

Actual behavior:
x narrows to x: {} and gives an error on x.val.

I think the reason is that constructor functions are special-cased in resolveCallExpression -- they still only have call signatures, not construct signatures. The code in narrowTypeByInstanceof probably needs the same special-casing (or to have it in one place).

@sandersn sandersn added Bug A bug in TypeScript Fixed A PR has been merged for this issue Domain: JavaScript The issue relates to JavaScript specifically labels Oct 4, 2018
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: JavaScript The issue relates to JavaScript specifically Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant