Skip to content

Better errors for types with same name #1575

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

chrisbubernak
Copy link
Contributor

Fix for issue #1419. Added a pretty unobtrusive fix but I'm wondering if I need to have more complicated logic (like typeToString() does) to handle certain cases that simply calling getFullyQualifiedName doesn't take care of.

@@ -1,6 +1,6 @@
tests/cases/compiler/clodulesDerivedClasses.ts(9,7): error TS2417: Class static side 'typeof Path' incorrectly extends base class static side 'typeof Shape'.
Types of property 'Utils' are incompatible.
Type 'typeof Utils' is not assignable to type 'typeof Utils'.
Type 'Path.Utils' is not assignable to type 'Shape.Utils'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually a regression - I think it should be 'typeof Path.Utils' and 'typeof Shape.Utils'.

@DanielRosenwasser
Copy link
Member

I think you'll need to modify typeToString. Offhandedly, I'd add a flag like FullyQualifyName to TypeFormatFlags (in types.ts). @CyrusNajmabadi and @sheetalkamat would know better than I would.

@chrisbubernak
Copy link
Contributor Author

Makes sense. I'll try something along those lines and see what I come up with.

@@ -1096,9 +1096,11 @@ module ts {
}

// Get qualified name
if (enclosingDeclaration &&
if ((enclosingDeclaration &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please find a way to simplify this 'if' conditional. One option is to introduce locals above to make it clearer what you are testing for.


// Get qualified name if there is an enclosing declaration and it is not a
// type parameter or we have a flag telling us to
var needFullyQualifiedName = (enclosingDeclaration && !(symbol.flags & SymbolFlags.TypeParameter));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type parameters still shouldn't be qualified even when TypeFormatFlags.UseFullyQualifiedType

…eparemeters even if typeformatflag is present
}
else if (typeStack && contains(typeStack, type)) {
// If type is an anonymous type literal in a type alias declaration, use type alias name
var typeAlias = getTypeAliasForTypeLiteral(type);
if (typeAlias) {
buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type);
buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type, /*flags*/ undefined, flags);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use None, not undefined.

@DanielRosenwasser
Copy link
Member

Need to bring this back up on the radar - sorry for the lack of follow-up. I'll try to CR it when I get in.


// Get qualified name if the symbol is not a type parameter
// and there is an enclosing declaration or we specifically
// asked for it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align indentation

@DanielRosenwasser
Copy link
Member

Looking good so far! Just need to address the comments I've left.

@chrisbubernak
Copy link
Contributor Author

Sweet, I'll get it fixed up when I get a chance.

@DanielRosenwasser
Copy link
Member

LGTM 👍

@chrisbubernak
Copy link
Contributor Author

@DanielRosenwasser Any other work that needs to be done here?

@DanielRosenwasser
Copy link
Member

I don't think so, but I'd like to just get sign off from another member before pulling in the change.

@mhegazy @JsonFreeman @yuit

DanielRosenwasser added a commit that referenced this pull request Jan 31, 2015
…ameName

Better errors for types with same name
@DanielRosenwasser DanielRosenwasser merged commit e174fe4 into microsoft:master Jan 31, 2015
@DanielRosenwasser
Copy link
Member

Thanks! This is going to save users a lot of mental anguish. 😄

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

None yet

4 participants