Skip to content

Add error message #10446

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

Merged
merged 6 commits into from
Aug 23, 2016
Merged

Add error message #10446

merged 6 commits into from
Aug 23, 2016

Conversation

YuichiNukiyama
Copy link
Contributor

Fixes #10351
Reference https://developer.mozilla.org/en-US/docs/Glossary/Primitive
Add error message when trying to relate primitives to the boxed/apparent backing types.

Add error message when trying to relate primitives to the boxed/apparent
backing types.
@@ -6258,6 +6258,13 @@ namespace ts {
targetType = typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
}

// check if trying to relate primitives to the boxed/apparent backing types.
if ((sourceType === "Number" && targetType === "number") ||
Copy link
Member

Choose a reason for hiding this comment

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

You don't want to do this because you might be in a context where Number has been shadowed to something else.

You also need to cover Symbol/symbol.

Instead, do a check against

  • globalStringType/stringType
  • globalNumberType/numberType
  • globalBooleanType/booleanType
  • getGlobalESSymbolType()/esSymbolType

Copy link
Member

@DanielRosenwasser DanielRosenwasser Aug 20, 2016

Choose a reason for hiding this comment

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

Also, I don't think you necessarily want to do this here. I think you want to have a separate function for this logic right before this line in isRelatedTo:

if (reportErrors) {
    reportRelationError(headMessage, source, target);
}

So before that, I'd have a check like

if (source.flags & TypeFlags.ObjectType && target.flags & TypeFlags.Primitive) {
    tryElaborateErrorsForPrimitivesAndObjects(source, target);
}

@DanielRosenwasser
Copy link
Member

Looks like a nice improvement in the baselines! 😄

@YuichiNukiyama
Copy link
Contributor Author

YuichiNukiyama commented Aug 20, 2016

@DanielRosenwasser Thanks your kindfull advise. I have no idea why some tests fail. Do you have any ideas?

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Aug 20, 2016

Whoops - that's being caused by the assertion in reportError. Basically you'll need to move the new change into the

if (reportErrors) {
    // ...
}

block in isRelatedTo.

@YuichiNukiyama
Copy link
Contributor Author

@DanielRosenwasser Nice 👍 I could resolve my issues.

@DanielRosenwasser
Copy link
Member

Nice job! @RyanCavanaugh and @sandersn, any feedback?

@RyanCavanaugh
Copy link
Member

The ES spec refers to these as "wrapper objects" and doesn't use the term "box". I would prefer something like

'string' is a primitive, but 'String' is a wrapper object. Prefer using 'string' when possible.

Thoughts?

@DanielRosenwasser
Copy link
Member

Let's go with Ryan's suggestion and I think we'll be good to pull in.

@YuichiNukiyama
Copy link
Contributor Author

change error message.

@sandersn sandersn merged commit ddb5a00 into microsoft:master Aug 23, 2016
@YuichiNukiyama YuichiNukiyama deleted the fix10351 branch August 23, 2016 21:34
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 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.

5 participants