Skip to content
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

Improve error message for using value as type #29896

Merged
merged 3 commits into from
Feb 14, 2019

Conversation

dragomirtitian
Copy link
Contributor

Fixes #29778.

The new error message is in most casses an improvement over the old. There are a few corner casses where there are already other errors and the new message might not be helpful, but I would like an opinion on them

  1. Self referencing variable.
var hasOwnProperty: hasOwnProperty; // Error
// Previous tests/cases/compiler/intrinsics.ts(1,21): error TS2304: Cannot find name 'hasOwnProperty'.
///Current tests/cases/compiler/intrinsics.ts(1,21): error TS2749: 'hasOwnProperty' refers to a value, but is being used as a type here.

If this is deemed too confusing, I could check that the found symbol declaration is not a parent of the node being checked.

  1. Duplicate symbols
declare class Point
{
    x: number;
    y: number;
    constructor(x: number, y: number);

     add(dx: number, dy: number): Point; 
//!!! error TS2304: Cannot find name 'Point'.
//!!! error TS2749: 'Point' refers to a value, but is being used as a type here.
}

function Point(x, y) {
    this.x = x;
    this.y = y;

    return this;
}

This one I am not sure how to revert back to the old error, ideally I would not report the new error message if the found symbol has a duplicate, but I have not found a wat to access this information in resolveName.

@RyanCavanaugh
Copy link
Member

Looks great. I think the edge cases are no more confusing than the prior version.

@RyanCavanaugh RyanCavanaugh merged commit cc987a1 into microsoft:master Feb 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error message for using value as type
2 participants