-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11717 from Microsoft/normalizeIntersectionTypes
Normalize union/intersection type combinations
- Loading branch information
Showing
10 changed files
with
722 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
tests/baselines/reference/intersectionTypeNormalization.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
//// [intersectionTypeNormalization.ts] | ||
interface A { a: string } | ||
interface B { b: string } | ||
interface C { c: string } | ||
interface D { d: string } | ||
|
||
// Identical ways of writing the same type | ||
type X1 = (A | B) & (C | D); | ||
type X2 = A & (C | D) | B & (C | D) | ||
type X3 = A & C | A & D | B & C | B & D; | ||
|
||
var x: X1; | ||
var x: X2; | ||
var x: X3; | ||
|
||
interface X { x: string } | ||
interface Y { y: string } | ||
|
||
// Identical ways of writing the same type | ||
type Y1 = (A | X & Y) & (C | D); | ||
type Y2 = A & (C | D) | X & Y & (C | D) | ||
type Y3 = A & C | A & D | X & Y & C | X & Y & D; | ||
|
||
var y: Y1; | ||
var y: Y2; | ||
var y: Y3; | ||
|
||
interface M { m: string } | ||
interface N { n: string } | ||
|
||
// Identical ways of writing the same type | ||
type Z1 = (A | X & (M | N)) & (C | D); | ||
type Z2 = A & (C | D) | X & (M | N) & (C | D) | ||
type Z3 = A & C | A & D | X & (M | N) & C | X & (M | N) & D; | ||
type Z4 = A & C | A & D | X & M & C | X & N & C | X & M & D | X & N & D; | ||
|
||
var z: Z1; | ||
var z: Z2; | ||
var z: Z3; | ||
var z: Z4; | ||
|
||
// Repro from #9919 | ||
|
||
type ToString = { | ||
toString(): string; | ||
} | ||
|
||
type BoxedValue = { kind: 'int', num: number } | ||
| { kind: 'string', str: string } | ||
|
||
type IntersectionFail = BoxedValue & ToString | ||
|
||
type IntersectionInline = { kind: 'int', num: number } & ToString | ||
| { kind: 'string', str: string } & ToString | ||
|
||
function getValueAsString(value: IntersectionFail): string { | ||
if (value.kind === 'int') { | ||
return '' + value.num; | ||
} | ||
return value.str; | ||
} | ||
|
||
//// [intersectionTypeNormalization.js] | ||
var x; | ||
var x; | ||
var x; | ||
var y; | ||
var y; | ||
var y; | ||
var z; | ||
var z; | ||
var z; | ||
var z; | ||
function getValueAsString(value) { | ||
if (value.kind === 'int') { | ||
return '' + value.num; | ||
} | ||
return value.str; | ||
} |
Oops, something went wrong.