Skip to content

Merge master1128 #12546

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 33 commits into from
Nov 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
443abe5
Allow one leading ignored “|” or “&” in a type position
mariusschulz Nov 19, 2016
e45c5db
Add tests and accept new baselines
mariusschulz Nov 19, 2016
cd70f22
Add “|” and “&” to list of tokens that start a type
mariusschulz Nov 20, 2016
d040db4
Add test for proper tuple type handling
mariusschulz Nov 20, 2016
cdda5df
keyof T is a literal contextual type
ahejlsberg Nov 24, 2016
2cec4c5
Add regression test
ahejlsberg Nov 24, 2016
36ad772
Type inference for isomorphic mapped types
ahejlsberg Nov 24, 2016
7b37918
doc(compiler/ts): fix documentation typo about __decorator code gener…
charlypoly Nov 24, 2016
5ba678a
Merge pull request #12480 from Microsoft/keyofIsLiteralContext
ahejlsberg Nov 25, 2016
46ca0ba
Fix multiple 'keyof' issues with 'for-in' and 'in' operator
ahejlsberg Nov 26, 2016
a26a303
Accept new baselines
ahejlsberg Nov 26, 2016
12b63d2
Add regression test
ahejlsberg Nov 26, 2016
f2c32d2
Include mapped types in type inference infinite recursion check
ahejlsberg Nov 26, 2016
d1393a6
Add regression test
ahejlsberg Nov 26, 2016
5ab2fec
Merge pull request #12482 from wittydeveloper/fix-generateClassElemen…
mhegazy Nov 26, 2016
283c50c
Merge pull request #12514 from Microsoft/keyofAndForIn
ahejlsberg Nov 27, 2016
88b7d53
Merge pull request #12515 from Microsoft/fixMappedTypeInference
ahejlsberg Nov 27, 2016
0a1a3ec
Merge branch 'master' into mappedTypeInference
ahejlsberg Nov 27, 2016
ecd10be
Reorder type inference cases
ahejlsberg Nov 27, 2016
9971847
Add tests
ahejlsberg Nov 27, 2016
8ee5f7d
Remove unused case in type inference
ahejlsberg Nov 28, 2016
9970606
Remove unused code in resolveMappedTypeMembers
ahejlsberg Nov 28, 2016
8b7252c
Update keyof tests to reflect #12425
ethanresnick Nov 28, 2016
3e1b443
Deduplicate intersection types before distributing over union types
ahejlsberg Nov 28, 2016
0be4ede
Add regression test
ahejlsberg Nov 28, 2016
5b873fa
Merge pull request #12537 from Microsoft/fixIntersectionNormalization
ahejlsberg Nov 28, 2016
9065b50
getRegularTypeOfLiteralType before exhaustive switch check
ahejlsberg Nov 28, 2016
2b07216
Add regression test
ahejlsberg Nov 28, 2016
0d4beb0
Merge pull request #12538 from Microsoft/fixExhaustiveSwitchCheck
ahejlsberg Nov 28, 2016
9cac35b
Merge pull request #12533 from ethanresnick/keyof-tests
mhegazy Nov 28, 2016
5dd4c9e
Merge pull request #12528 from Microsoft/mappedTypeInference
ahejlsberg Nov 28, 2016
c89b1eb
Merge pull request #12386 from mariusschulz/union-and-intersection-ty…
ahejlsberg Nov 28, 2016
dd35a5d
Merge branch 'master' into release-2.1
mhegazy Nov 29, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 113 additions & 56 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2558,6 +2558,8 @@ namespace ts {
case SyntaxKind.OpenBraceToken:
case SyntaxKind.OpenBracketToken:
case SyntaxKind.LessThanToken:
case SyntaxKind.BarToken:
case SyntaxKind.AmpersandToken:
case SyntaxKind.NewKeyword:
case SyntaxKind.StringLiteral:
case SyntaxKind.NumericLiteral:
Expand Down Expand Up @@ -2617,6 +2619,7 @@ namespace ts {
}

function parseUnionOrIntersectionType(kind: SyntaxKind, parseConstituentType: () => TypeNode, operator: SyntaxKind): TypeNode {
parseOptional(operator);
let type = parseConstituentType();
if (token() === operator) {
const types = createNodeArray<TypeNode>([type], type.pos);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1353,13 +1353,13 @@ namespace ts {
// __metadata("design:type", Function),
// __metadata("design:paramtypes", [Object]),
// __metadata("design:returntype", void 0)
// ], C.prototype, "method", undefined);
// ], C.prototype, "method", null);
//
// The emit for an accessor is:
//
// __decorate([
// dec
// ], C.prototype, "accessor", undefined);
// ], C.prototype, "accessor", null);
//
// The emit for a property is:
//
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//// [exhaustiveSwitchWithWideningLiteralTypes.ts]

// Repro from #12529

class A {
readonly kind = "A"; // (property) A.kind: "A"
}

class B {
readonly kind = "B"; // (property) B.kind: "B"
}

function f(value: A | B): number {
switch(value.kind) {
case "A": return 0;
case "B": return 1;
}
}

//// [exhaustiveSwitchWithWideningLiteralTypes.js]
// Repro from #12529
var A = (function () {
function A() {
this.kind = "A"; // (property) A.kind: "A"
}
return A;
}());
var B = (function () {
function B() {
this.kind = "B"; // (property) B.kind: "B"
}
return B;
}());
function f(value) {
switch (value.kind) {
case "A": return 0;
case "B": return 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
=== tests/cases/compiler/exhaustiveSwitchWithWideningLiteralTypes.ts ===

// Repro from #12529

class A {
>A : Symbol(A, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 0, 0))

readonly kind = "A"; // (property) A.kind: "A"
>kind : Symbol(A.kind, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 3, 9))
}

class B {
>B : Symbol(B, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 5, 1))

readonly kind = "B"; // (property) B.kind: "B"
>kind : Symbol(B.kind, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 7, 9))
}

function f(value: A | B): number {
>f : Symbol(f, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 9, 1))
>value : Symbol(value, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 11, 11))
>A : Symbol(A, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 0, 0))
>B : Symbol(B, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 5, 1))

switch(value.kind) {
>value.kind : Symbol(kind, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 3, 9), Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 7, 9))
>value : Symbol(value, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 11, 11))
>kind : Symbol(kind, Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 3, 9), Decl(exhaustiveSwitchWithWideningLiteralTypes.ts, 7, 9))

case "A": return 0;
case "B": return 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
=== tests/cases/compiler/exhaustiveSwitchWithWideningLiteralTypes.ts ===

// Repro from #12529

class A {
>A : A

readonly kind = "A"; // (property) A.kind: "A"
>kind : "A"
>"A" : "A"
}

class B {
>B : B

readonly kind = "B"; // (property) B.kind: "B"
>kind : "B"
>"B" : "B"
}

function f(value: A | B): number {
>f : (value: A | B) => number
>value : A | B
>A : A
>B : B

switch(value.kind) {
>value.kind : "A" | "B"
>value : A | B
>kind : "A" | "B"

case "A": return 0;
>"A" : "A"
>0 : 0

case "B": return 1;
>"B" : "B"
>1 : 1
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(12,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'.
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(13,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'.
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(14,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'.
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(16,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'.
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(17,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'.
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(19,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'.
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(20,11): error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'.
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(30,16): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter
Expand All @@ -19,7 +17,7 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInv
tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts(43,17): error TS2361: The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter


==== tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts (19 errors) ====
==== tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInvalidOperands.ts (17 errors) ====
enum E { a }

var x: any;
Expand All @@ -42,11 +40,7 @@ tests/cases/conformance/expressions/binaryOperators/inOperator/inOperatorWithInv
!!! error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'.
var ra4 = a4 in x;
var ra5 = null in x;
~~~~
!!! error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'.
var ra6 = undefined in x;
~~~~~~~~~
!!! error TS2360: The left-hand side of an 'in' expression must be of type 'any', 'string', 'number', or 'symbol'.
var ra7 = E.a in x;
var ra8 = false in x;
~~~~~
Expand Down
50 changes: 50 additions & 0 deletions tests/baselines/reference/intersectionTypeNormalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,51 @@ function getValueAsString(value: IntersectionFail): string {
return '' + value.num;
}
return value.str;
}

// Repro from #12535

namespace enums {
export const enum A {
a1,
a2,
a3,
// ... elements omitted for the sake of clarity
a75,
a76,
a77,
}
export const enum B {
b1,
b2,
// ... elements omitted for the sake of clarity
b86,
b87,
}
export const enum C {
c1,
c2,
// ... elements omitted for the sake of clarity
c210,
c211,
}
export type Genre = A | B | C;
}

type Foo = {
genreId: enums.Genre;
};

type Bar = {
genreId: enums.Genre;
};

type FooBar = Foo & Bar;

function foo(so: any) {
const val = so as FooBar;
const isGenre = val.genreId;
return isGenre;
}

//// [intersectionTypeNormalization.js]
Expand All @@ -77,3 +122,8 @@ function getValueAsString(value) {
}
return value.str;
}
function foo(so) {
var val = so;
var isGenre = val.genreId;
return isGenre;
}
110 changes: 110 additions & 0 deletions tests/baselines/reference/intersectionTypeNormalization.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,113 @@ function getValueAsString(value: IntersectionFail): string {
>value : Symbol(value, Decl(intersectionTypeNormalization.ts, 54, 26))
>str : Symbol(str, Decl(intersectionTypeNormalization.ts, 47, 35))
}

// Repro from #12535

namespace enums {
>enums : Symbol(enums, Decl(intersectionTypeNormalization.ts, 59, 1))

export const enum A {
>A : Symbol(A, Decl(intersectionTypeNormalization.ts, 63, 17))

a1,
>a1 : Symbol(A.a1, Decl(intersectionTypeNormalization.ts, 64, 25))

a2,
>a2 : Symbol(A.a2, Decl(intersectionTypeNormalization.ts, 65, 11))

a3,
>a3 : Symbol(A.a3, Decl(intersectionTypeNormalization.ts, 66, 11))

// ... elements omitted for the sake of clarity
a75,
>a75 : Symbol(A.a75, Decl(intersectionTypeNormalization.ts, 67, 11))

a76,
>a76 : Symbol(A.a76, Decl(intersectionTypeNormalization.ts, 69, 12))

a77,
>a77 : Symbol(A.a77, Decl(intersectionTypeNormalization.ts, 70, 12))
}
export const enum B {
>B : Symbol(B, Decl(intersectionTypeNormalization.ts, 72, 5))

b1,
>b1 : Symbol(B.b1, Decl(intersectionTypeNormalization.ts, 73, 25))

b2,
>b2 : Symbol(B.b2, Decl(intersectionTypeNormalization.ts, 74, 11))

// ... elements omitted for the sake of clarity
b86,
>b86 : Symbol(B.b86, Decl(intersectionTypeNormalization.ts, 75, 11))

b87,
>b87 : Symbol(B.b87, Decl(intersectionTypeNormalization.ts, 77, 12))
}
export const enum C {
>C : Symbol(C, Decl(intersectionTypeNormalization.ts, 79, 5))

c1,
>c1 : Symbol(C.c1, Decl(intersectionTypeNormalization.ts, 80, 25))

c2,
>c2 : Symbol(C.c2, Decl(intersectionTypeNormalization.ts, 81, 11))

// ... elements omitted for the sake of clarity
c210,
>c210 : Symbol(C.c210, Decl(intersectionTypeNormalization.ts, 82, 11))

c211,
>c211 : Symbol(C.c211, Decl(intersectionTypeNormalization.ts, 84, 13))
}
export type Genre = A | B | C;
>Genre : Symbol(Genre, Decl(intersectionTypeNormalization.ts, 86, 5))
>A : Symbol(A, Decl(intersectionTypeNormalization.ts, 63, 17))
>B : Symbol(B, Decl(intersectionTypeNormalization.ts, 72, 5))
>C : Symbol(C, Decl(intersectionTypeNormalization.ts, 79, 5))
}

type Foo = {
>Foo : Symbol(Foo, Decl(intersectionTypeNormalization.ts, 88, 1))

genreId: enums.Genre;
>genreId : Symbol(genreId, Decl(intersectionTypeNormalization.ts, 90, 12))
>enums : Symbol(enums, Decl(intersectionTypeNormalization.ts, 59, 1))
>Genre : Symbol(enums.Genre, Decl(intersectionTypeNormalization.ts, 86, 5))

};

type Bar = {
>Bar : Symbol(Bar, Decl(intersectionTypeNormalization.ts, 92, 2))

genreId: enums.Genre;
>genreId : Symbol(genreId, Decl(intersectionTypeNormalization.ts, 94, 12))
>enums : Symbol(enums, Decl(intersectionTypeNormalization.ts, 59, 1))
>Genre : Symbol(enums.Genre, Decl(intersectionTypeNormalization.ts, 86, 5))

};

type FooBar = Foo & Bar;
>FooBar : Symbol(FooBar, Decl(intersectionTypeNormalization.ts, 96, 2))
>Foo : Symbol(Foo, Decl(intersectionTypeNormalization.ts, 88, 1))
>Bar : Symbol(Bar, Decl(intersectionTypeNormalization.ts, 92, 2))

function foo(so: any) {
>foo : Symbol(foo, Decl(intersectionTypeNormalization.ts, 98, 24))
>so : Symbol(so, Decl(intersectionTypeNormalization.ts, 100, 13))

const val = so as FooBar;
>val : Symbol(val, Decl(intersectionTypeNormalization.ts, 101, 9))
>so : Symbol(so, Decl(intersectionTypeNormalization.ts, 100, 13))
>FooBar : Symbol(FooBar, Decl(intersectionTypeNormalization.ts, 96, 2))

const isGenre = val.genreId;
>isGenre : Symbol(isGenre, Decl(intersectionTypeNormalization.ts, 102, 9))
>val.genreId : Symbol(genreId, Decl(intersectionTypeNormalization.ts, 90, 12), Decl(intersectionTypeNormalization.ts, 94, 12))
>val : Symbol(val, Decl(intersectionTypeNormalization.ts, 101, 9))
>genreId : Symbol(genreId, Decl(intersectionTypeNormalization.ts, 90, 12), Decl(intersectionTypeNormalization.ts, 94, 12))

return isGenre;
>isGenre : Symbol(isGenre, Decl(intersectionTypeNormalization.ts, 102, 9))
}
Loading