Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

For $ExpectType assertions, alphabetically sort unions and intersections #61

Closed
wants to merge 4 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Aug 22, 2017

Not a perfect solution to microsoft/TypeScript#17944 as it operates on strings and thus can't delve into types easily, but should be enough to fix our test failures for now.
When this is merged I'll have to update all the tests on DT to align with this at the same time this is published.

@DanielRosenwasser
Copy link
Member

There's going to be an immediate limitation with type literals containing unions (i.e. { a: number | string }). Does that not come up in DefinitelyTyped?

@ghost ghost force-pushed the fixupUnions branch from 9d9a1bb to 7f98937 Compare August 22, 2017 18:31
@ghost
Copy link
Author

ghost commented Aug 22, 2017

I didn't see a lot, so added code to just skip anything with an object literal in it for now.

@@ -308,6 +309,27 @@ function getExpectTypeFailures(
}
}

function fixupType(s: string): string {
// Don't mess up `{ a: number | string }` into `string } | { a: number`
if (s.includes("{")) {
Copy link
Member

Choose a reason for hiding this comment

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

or <, (, [

@DanielRosenwasser
Copy link
Member

If we don't expect this to work perfectly, why not try to see if the current ones are identical, then try the adjustment as a fallback mechanism? Does that sound reasonable?

@microsoft microsoft deleted a comment from msftclas Sep 27, 2017
@@ -298,7 +298,12 @@ function getExpectTypeFailures(

const actual = checker.typeToString(type, /*enclosingDeclaration*/ undefined, ts.TypeFormatFlags.NoTruncation);
if (actual !== expected) {
unmetExpectations.push({ node, expected, actual });
console.log("!!!", actual);
Copy link

@fbartho fbartho Apr 11, 2018

Choose a reason for hiding this comment

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

Debug logs probably need to be cleaned up in this method/if-block?

This pull request was closed.
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.

4 participants