Skip to content

Fix #10991: Add improved error messages for comparison with narrowed types #22319

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

jack-williams
Copy link
Collaborator

@jack-williams jack-williams commented Mar 4, 2018

Fixes #10991

I think the error reporting I've implemented could be improved but it is probably worth discussing--just getting the ball rolling for now.

Ideas to consider.

  • Should the pre and post narrow types be presented (that is what it does now).
  • Should the error node be the operator or the narrowed reference (currently it is the same node as the parent error).

@RyanCavanaugh

Example:

const enum Keys {
    Tab = 10,
    Shift = 13
}

function enumType() {
    let key: Keys;

    if (key === Keys.Tab) {
        return;
    }

    if (key === Keys.Tab || key === Keys.Shift) {
    // Operator '===' cannot be applied to types 'Keys.Shift' and 'Keys.Tab'. [2365]
    // Earlier code in this block narrowed type 'Keys' to 'Keys.Shift' making this operation invalid. [2725]
        console.log('Bug');
    }
}

@jack-williams
Copy link
Collaborator Author

Failed CI is due to timeout on largeControlFlowGraph.ts. Can this happen coincidentally?

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 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.

1 participant