Skip to content

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
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
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.

Improve error message for using value as type

2 participants