Skip to content

#27370 breaks narrowing for constructor functions #27550

Closed

Description

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).

Activity

  1. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JavaScriptThe issue relates to JavaScript specificallyFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions