diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ffa7a69fbd893..54e6d31f15d8c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13268,6 +13268,11 @@ namespace ts { isUnitType(type); } + function isStringOrNumericLiteralType(type: Type): boolean { + return type.flags & TypeFlags.Union ? every((type).types, t => !!(t.flags & TypeFlags.StringOrNumberLiteral && !(t.flags & (TypeFlags.EnumLike | TypeFlags.Intrinsic)))) : + !!(type.flags & TypeFlags.StringOrNumberLiteral) && !(type.flags & (TypeFlags.EnumLike | TypeFlags.Intrinsic)); + } + function getBaseTypeOfLiteralType(type: Type): Type { return type.flags & TypeFlags.EnumLiteral ? getBaseTypeOfEnumLiteralType(type) : type.flags & TypeFlags.StringLiteral ? stringType : @@ -21828,6 +21833,21 @@ namespace ts { return numberType; } + function checkUnaryExpression(node: PrefixUnaryExpression | PostfixUnaryExpression): Type { + const symbol = isEntityNameExpression(node.operand) ? isPropertyAccessEntityNameExpression(node.operand) ? + getSymbolAtLocation((node.operand).name) : getResolvedSymbol(node.operand) : undefined; + if (symbol && isUnaryAssignmentOperator(node.operator) && !(getDeclarationNodeFlagsFromSymbol(symbol) & NodeFlags.Const)) { + const operandType = getTypeOfSymbol(symbol); + if (isStringOrNumericLiteralType(operandType)) { + error(node.operand, Diagnostics.The_literal_type_0_cannot_be_modified, typeToString(operandType)); + } + } + if (node.kind === SyntaxKind.PrefixUnaryExpression) { + return checkPrefixUnaryExpression(node); + } + return checkPostfixUnaryExpression(node); + } + // Return true if type might be of the given kind. A union or intersection type might be of a given // kind if at least one constituent type is of the given kind. function maybeTypeOfKind(type: Type, kind: TypeFlags): boolean { @@ -22170,10 +22190,19 @@ namespace ts { function checkBinaryLikeExpression(left: Expression, operatorToken: Node, right: Expression, checkMode?: CheckMode, errorNode?: Node): Type { const operator = operatorToken.kind; + let leftType: Type; + + const symbol = isEntityNameExpression(left) ? isPropertyAccessEntityNameExpression(left) ? + getSymbolAtLocation((left).name) : getResolvedSymbol(left) : undefined; + if (symbol && isCompoundAssignmentOperator(operator) && !(getDeclarationNodeFlagsFromSymbol(symbol) & NodeFlags.Const)) { + leftType = getTypeOfSymbol(getResolvedSymbol(left as Identifier)); + if (isStringOrNumericLiteralType(leftType)) { + error(left, Diagnostics.The_literal_type_0_cannot_be_modified, typeToString(leftType)); + } + } if (operator === SyntaxKind.EqualsToken && (left.kind === SyntaxKind.ObjectLiteralExpression || left.kind === SyntaxKind.ArrayLiteralExpression)) { return checkDestructuringAssignment(left, checkExpression(right, checkMode), checkMode, right.kind === SyntaxKind.ThisKeyword); } - let leftType: Type; if (operator === SyntaxKind.AmpersandAmpersandToken || operator === SyntaxKind.BarBarToken) { leftType = checkTruthinessExpression(left, checkMode); } @@ -22866,9 +22895,8 @@ namespace ts { case SyntaxKind.AwaitExpression: return checkAwaitExpression(node); case SyntaxKind.PrefixUnaryExpression: - return checkPrefixUnaryExpression(node); case SyntaxKind.PostfixUnaryExpression: - return checkPostfixUnaryExpression(node); + return checkUnaryExpression(node); case SyntaxKind.BinaryExpression: return checkBinaryExpression(node, checkMode); case SyntaxKind.ConditionalExpression: diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e3f8e1a7ad5a6..64509c64eb3e3 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2529,6 +2529,10 @@ "category": "Error", "code": 2742 }, + "The literal type '{0}' cannot be modified.": { + "category": "Error", + "code": 2743 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 6b1778aab3050..6deef72db84f6 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3839,6 +3839,27 @@ namespace ts { || token === SyntaxKind.ExclamationToken; } + export function isCompoundAssignmentOperator(token: SyntaxKind): boolean { + return token === SyntaxKind.PlusEqualsToken + || token === SyntaxKind.MinusEqualsToken + || token === SyntaxKind.AsteriskAsteriskEqualsToken + || token === SyntaxKind.AsteriskEqualsToken + || token === SyntaxKind.SlashEqualsToken + || token === SyntaxKind.PercentEqualsToken + || token === SyntaxKind.AmpersandEqualsToken + || token === SyntaxKind.BarEqualsToken + || token === SyntaxKind.CaretEqualsToken + || token === SyntaxKind.LessThanLessThanEqualsToken + || token === SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken + || token === SyntaxKind.GreaterThanGreaterThanEqualsToken; + } + + export function isUnaryAssignmentOperator(token: SyntaxKind): boolean { + return token === SyntaxKind.PlusPlusToken + || token === SyntaxKind.MinusMinusToken; + + } + export function isAssignmentOperator(token: SyntaxKind): boolean { return token >= SyntaxKind.FirstAssignment && token <= SyntaxKind.LastAssignment; } diff --git a/tests/baselines/reference/literalTypeProperty.errors.txt b/tests/baselines/reference/literalTypeProperty.errors.txt new file mode 100644 index 0000000000000..671e7e7ba05d6 --- /dev/null +++ b/tests/baselines/reference/literalTypeProperty.errors.txt @@ -0,0 +1,58 @@ +tests/cases/conformance/types/literal/literalTypeProperty.ts(7,1): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/literalTypeProperty.ts(8,1): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/literalTypeProperty.ts(9,1): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/literalTypeProperty.ts(10,1): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/literalTypeProperty.ts(11,3): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/literalTypeProperty.ts(12,3): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/literalTypeProperty.ts(14,1): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/literalTypeProperty.ts(15,1): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/literalTypeProperty.ts(16,1): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/literalTypeProperty.ts(17,1): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/literalTypeProperty.ts(18,3): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/literalTypeProperty.ts(19,3): error TS2743: The literal type '10 | 11' cannot be modified. + + +==== tests/cases/conformance/types/literal/literalTypeProperty.ts (12 errors) ==== + declare class C { + foo: 10; + bar: 10 | 11 + } + + var o = new C() + o.foo ++ + ~~~~~ +!!! error TS2743: The literal type '10' cannot be modified. + o.foo += 1 + ~~~~~ +!!! error TS2743: The literal type '10' cannot be modified. + o.foo -= 1 + ~~~~~ +!!! error TS2743: The literal type '10' cannot be modified. + o.foo -- + ~~~~~ +!!! error TS2743: The literal type '10' cannot be modified. + ++o.foo + ~~~~~ +!!! error TS2743: The literal type '10' cannot be modified. + --o.foo + ~~~~~ +!!! error TS2743: The literal type '10' cannot be modified. + + o.bar ++ + ~~~~~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + o.bar += 1 + ~~~~~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + o.bar -= 1 + ~~~~~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + o.bar -- + ~~~~~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + ++o.bar + ~~~~~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + --o.bar + ~~~~~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. \ No newline at end of file diff --git a/tests/baselines/reference/literalTypeProperty.js b/tests/baselines/reference/literalTypeProperty.js new file mode 100644 index 0000000000000..da0c7ff09e01b --- /dev/null +++ b/tests/baselines/reference/literalTypeProperty.js @@ -0,0 +1,35 @@ +//// [literalTypeProperty.ts] +declare class C { + foo: 10; + bar: 10 | 11 +} + +var o = new C() +o.foo ++ +o.foo += 1 +o.foo -= 1 +o.foo -- +++o.foo +--o.foo + +o.bar ++ +o.bar += 1 +o.bar -= 1 +o.bar -- +++o.bar +--o.bar + +//// [literalTypeProperty.js] +var o = new C(); +o.foo++; +o.foo += 1; +o.foo -= 1; +o.foo--; +++o.foo; +--o.foo; +o.bar++; +o.bar += 1; +o.bar -= 1; +o.bar--; +++o.bar; +--o.bar; diff --git a/tests/baselines/reference/literalTypeProperty.symbols b/tests/baselines/reference/literalTypeProperty.symbols new file mode 100644 index 0000000000000..d673c4d11b76c --- /dev/null +++ b/tests/baselines/reference/literalTypeProperty.symbols @@ -0,0 +1,75 @@ +=== tests/cases/conformance/types/literal/literalTypeProperty.ts === +declare class C { +>C : Symbol(C, Decl(literalTypeProperty.ts, 0, 0)) + + foo: 10; +>foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17)) + + bar: 10 | 11 +>bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10)) +} + +var o = new C() +>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3)) +>C : Symbol(C, Decl(literalTypeProperty.ts, 0, 0)) + +o.foo ++ +>o.foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17)) +>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3)) +>foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17)) + +o.foo += 1 +>o.foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17)) +>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3)) +>foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17)) + +o.foo -= 1 +>o.foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17)) +>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3)) +>foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17)) + +o.foo -- +>o.foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17)) +>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3)) +>foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17)) + +++o.foo +>o.foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17)) +>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3)) +>foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17)) + +--o.foo +>o.foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17)) +>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3)) +>foo : Symbol(C.foo, Decl(literalTypeProperty.ts, 0, 17)) + +o.bar ++ +>o.bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10)) +>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3)) +>bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10)) + +o.bar += 1 +>o.bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10)) +>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3)) +>bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10)) + +o.bar -= 1 +>o.bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10)) +>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3)) +>bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10)) + +o.bar -- +>o.bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10)) +>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3)) +>bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10)) + +++o.bar +>o.bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10)) +>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3)) +>bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10)) + +--o.bar +>o.bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10)) +>o : Symbol(o, Decl(literalTypeProperty.ts, 5, 3)) +>bar : Symbol(C.bar, Decl(literalTypeProperty.ts, 1, 10)) + diff --git a/tests/baselines/reference/literalTypeProperty.types b/tests/baselines/reference/literalTypeProperty.types new file mode 100644 index 0000000000000..f4010d1ef3b7c --- /dev/null +++ b/tests/baselines/reference/literalTypeProperty.types @@ -0,0 +1,92 @@ +=== tests/cases/conformance/types/literal/literalTypeProperty.ts === +declare class C { +>C : C + + foo: 10; +>foo : 10 + + bar: 10 | 11 +>bar : 10 | 11 +} + +var o = new C() +>o : C +>new C() : C +>C : typeof C + +o.foo ++ +>o.foo ++ : number +>o.foo : number +>o : C +>foo : number + +o.foo += 1 +>o.foo += 1 : number +>o.foo : number +>o : C +>foo : number +>1 : 1 + +o.foo -= 1 +>o.foo -= 1 : number +>o.foo : number +>o : C +>foo : number +>1 : 1 + +o.foo -- +>o.foo -- : number +>o.foo : number +>o : C +>foo : number + +++o.foo +>++o.foo : number +>o.foo : number +>o : C +>foo : number + +--o.foo +>--o.foo : number +>o.foo : number +>o : C +>foo : number + +o.bar ++ +>o.bar ++ : number +>o.bar : number +>o : C +>bar : number + +o.bar += 1 +>o.bar += 1 : number +>o.bar : number +>o : C +>bar : number +>1 : 1 + +o.bar -= 1 +>o.bar -= 1 : number +>o.bar : number +>o : C +>bar : number +>1 : 1 + +o.bar -- +>o.bar -- : number +>o.bar : number +>o : C +>bar : number + +++o.bar +>++o.bar : number +>o.bar : number +>o : C +>bar : number + +--o.bar +>--o.bar : number +>o.bar : number +>o : C +>bar : number + diff --git a/tests/baselines/reference/numericLiteralTypes1.errors.txt b/tests/baselines/reference/numericLiteralTypes1.errors.txt new file mode 100644 index 0000000000000..8b497cc449d8f --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes1.errors.txt @@ -0,0 +1,148 @@ +tests/cases/conformance/types/literal/numericLiteralTypes1.ts(48,5): error TS2743: The literal type '1' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes1.ts(49,5): error TS2743: The literal type '0 | 1 | 2' cannot be modified. + + +==== tests/cases/conformance/types/literal/numericLiteralTypes1.ts (2 errors) ==== + type A1 = 1; + type A2 = 1.0; + type A3 = 1e0; + type A4 = 10e-1; + type A5 = 1 | 1.0 | 1e0 | 10e-1; + + function f1() { + var a: A1 = 1; + var a: A2 = 1; + var a: A3 = 1; + var a: A4 = 1; + var a: A5 = 1; + } + + type B1 = -1 | 0 | 1; + type B2 = 1 | 0 | -1; + type B3 = 0 | -1 | 1; + + function f2() { + var b: B1 = -1; + var b: B2 = 0; + var b: B3 = 1; + } + + function f3(a: 1, b: 0 | 1 | 2) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; + } + + function f4(a: 1, b: 0 | 1 | 2) { + a++; + ~ +!!! error TS2743: The literal type '1' cannot be modified. + b++; + ~ +!!! error TS2743: The literal type '0 | 1 | 2' cannot be modified. + } + + declare function g(x: 0): string; + declare function g(x: 1): boolean; + declare function g(x: number): number; + + function f5(a: 1, b: 0 | 1 | 2) { + var z1 = g(0); + var z2 = g(1); + var z3 = g(2); + var z4 = g(a); + var z5 = g(b); + } + + function assertNever(x: never): never { + throw new Error("Unexpected value"); + } + + type Tag = 0 | 1 | 2; + + function f10(x: Tag) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } + } + + function f11(x: Tag) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } + return assertNever(x); + } + + function f12(x: Tag) { + if (x) { + x; + } + else { + x; + } + } + + function f13(x: Tag) { + if (x === 0 || x === 2) { + x; + } + else { + x; + } + } + + function f14(x: 0 | 1 | 2, y: string) { + var a = x && y; + var b = x || y; + } + + function f15(x: 0 | false, y: 1 | "one") { + var a = x && y; + var b = y && x; + var c = x || y; + var d = y || x; + var e = !x; + var f = !y; + } + + type Item = + { kind: 0, a: string } | + { kind: 1, b: string } | + { kind: 2, c: string }; + + function f20(x: Item) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } + } + + function f21(x: Item) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } + return assertNever(x); + } \ No newline at end of file diff --git a/tests/baselines/reference/numericLiteralTypes2.errors.txt b/tests/baselines/reference/numericLiteralTypes2.errors.txt new file mode 100644 index 0000000000000..082fb93d2f23e --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes2.errors.txt @@ -0,0 +1,148 @@ +tests/cases/conformance/types/literal/numericLiteralTypes2.ts(48,5): error TS2743: The literal type '1' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes2.ts(49,5): error TS2743: The literal type '0 | 1 | 2' cannot be modified. + + +==== tests/cases/conformance/types/literal/numericLiteralTypes2.ts (2 errors) ==== + type A1 = 1; + type A2 = 1.0; + type A3 = 1e0; + type A4 = 10e-1; + type A5 = 1 | 1.0 | 1e0 | 10e-1; + + function f1() { + var a: A1 = 1; + var a: A2 = 1; + var a: A3 = 1; + var a: A4 = 1; + var a: A5 = 1; + } + + type B1 = -1 | 0 | 1; + type B2 = 1 | 0 | -1; + type B3 = 0 | -1 | 1; + + function f2() { + var b: B1 = -1; + var b: B2 = 0; + var b: B3 = 1; + } + + function f3(a: 1, b: 0 | 1 | 2) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; + } + + function f4(a: 1, b: 0 | 1 | 2) { + a++; + ~ +!!! error TS2743: The literal type '1' cannot be modified. + b++; + ~ +!!! error TS2743: The literal type '0 | 1 | 2' cannot be modified. + } + + declare function g(x: 0): string; + declare function g(x: 1): boolean; + declare function g(x: number): number; + + function f5(a: 1, b: 0 | 1 | 2) { + var z1 = g(0); + var z2 = g(1); + var z3 = g(2); + var z4 = g(a); + var z5 = g(b); + } + + function assertNever(x: never): never { + throw new Error("Unexpected value"); + } + + type Tag = 0 | 1 | 2; + + function f10(x: Tag) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } + } + + function f11(x: Tag) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } + return assertNever(x); + } + + function f12(x: Tag) { + if (x) { + x; + } + else { + x; + } + } + + function f13(x: Tag) { + if (x === 0 || x === 2) { + x; + } + else { + x; + } + } + + function f14(x: 0 | 1 | 2, y: string) { + var a = x && y; + var b = x || y; + } + + function f15(x: 0 | false, y: 1 | "one") { + var a = x && y; + var b = y && x; + var c = x || y; + var d = y || x; + var e = !x; + var f = !y; + } + + type Item = + { kind: 0, a: string } | + { kind: 1, b: string } | + { kind: 2, c: string }; + + function f20(x: Item) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } + } + + function f21(x: Item) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } + return assertNever(x); + } \ No newline at end of file diff --git a/tests/baselines/reference/numericLiteralTypes4.errors.txt b/tests/baselines/reference/numericLiteralTypes4.errors.txt new file mode 100644 index 0000000000000..2490104e6f403 --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes4.errors.txt @@ -0,0 +1,192 @@ +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(5,1): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(6,1): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(7,1): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(8,1): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(9,1): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(10,1): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(11,1): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(12,1): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(13,1): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(14,1): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(15,1): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(16,1): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(17,1): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(19,3): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(20,3): error TS2743: The literal type '10' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(22,1): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(23,1): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(24,1): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(25,1): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(26,1): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(27,1): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(28,1): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(29,1): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(30,1): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(31,1): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(32,1): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(33,1): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(34,1): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(36,3): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(37,3): error TS2743: The literal type '10 | 11' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(39,1): error TS2743: The literal type '10 | 11 | 12' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(40,1): error TS2743: The literal type '10 | 11 | 12' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(41,1): error TS2743: The literal type '10 | 11 | 12' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(42,1): error TS2743: The literal type '10 | 11 | 12' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(43,1): error TS2743: The literal type '10 | 11 | 12' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(44,1): error TS2743: The literal type '10 | 11 | 12' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(45,1): error TS2743: The literal type '10 | 11 | 12' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(46,1): error TS2743: The literal type '10 | 11 | 12' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(47,1): error TS2743: The literal type '10 | 11 | 12' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(48,1): error TS2743: The literal type '10 | 11 | 12' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(49,1): error TS2743: The literal type '10 | 11 | 12' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(50,1): error TS2743: The literal type '10 | 11 | 12' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(51,1): error TS2743: The literal type '10 | 11 | 12' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(53,3): error TS2743: The literal type '10 | 11 | 12' cannot be modified. +tests/cases/conformance/types/literal/numericLiteralTypes4.ts(54,3): error TS2743: The literal type '10 | 11 | 12' cannot be modified. + + +==== tests/cases/conformance/types/literal/numericLiteralTypes4.ts (45 errors) ==== + var a: 10 = 10; + var b: 10 | 11 = 11; + var c: 10 | 11 | 12 = 10; + + a ++; + ~ +!!! error TS2743: The literal type '10' cannot be modified. + a --; + ~ +!!! error TS2743: The literal type '10' cannot be modified. + a += 1; + ~ +!!! error TS2743: The literal type '10' cannot be modified. + a -= 1; + ~ +!!! error TS2743: The literal type '10' cannot be modified. + a *= 1; + ~ +!!! error TS2743: The literal type '10' cannot be modified. + a /= 1; + ~ +!!! error TS2743: The literal type '10' cannot be modified. + a %= 1; + ~ +!!! error TS2743: The literal type '10' cannot be modified. + a &= 1; + ~ +!!! error TS2743: The literal type '10' cannot be modified. + a |= 1; + ~ +!!! error TS2743: The literal type '10' cannot be modified. + a ^= 1; + ~ +!!! error TS2743: The literal type '10' cannot be modified. + a >>= 1; + ~ +!!! error TS2743: The literal type '10' cannot be modified. + a >>>= 1; + ~ +!!! error TS2743: The literal type '10' cannot be modified. + a <<= 1; + ~ +!!! error TS2743: The literal type '10' cannot be modified. + + ++a + ~ +!!! error TS2743: The literal type '10' cannot be modified. + --a + ~ +!!! error TS2743: The literal type '10' cannot be modified. + + b ++; + ~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + b --; + ~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + b += 1; + ~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + b -= 1; + ~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + b *= 1; + ~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + b /= 1; + ~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + b %= 1; + ~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + b &= 1; + ~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + b |= 1; + ~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + b ^= 1; + ~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + b >>= 1; + ~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + b >>>= 1; + ~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + b <<= 1; + ~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + + ++b + ~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + --b + ~ +!!! error TS2743: The literal type '10 | 11' cannot be modified. + + c ++; + ~ +!!! error TS2743: The literal type '10 | 11 | 12' cannot be modified. + c --; + ~ +!!! error TS2743: The literal type '10 | 11 | 12' cannot be modified. + c += 1; + ~ +!!! error TS2743: The literal type '10 | 11 | 12' cannot be modified. + c -= 1; + ~ +!!! error TS2743: The literal type '10 | 11 | 12' cannot be modified. + c *= 1; + ~ +!!! error TS2743: The literal type '10 | 11 | 12' cannot be modified. + c /= 1; + ~ +!!! error TS2743: The literal type '10 | 11 | 12' cannot be modified. + c %= 1; + ~ +!!! error TS2743: The literal type '10 | 11 | 12' cannot be modified. + c &= 1; + ~ +!!! error TS2743: The literal type '10 | 11 | 12' cannot be modified. + c |= 1; + ~ +!!! error TS2743: The literal type '10 | 11 | 12' cannot be modified. + c ^= 1; + ~ +!!! error TS2743: The literal type '10 | 11 | 12' cannot be modified. + c >>= 1; + ~ +!!! error TS2743: The literal type '10 | 11 | 12' cannot be modified. + c >>>= 1; + ~ +!!! error TS2743: The literal type '10 | 11 | 12' cannot be modified. + c <<= 1; + ~ +!!! error TS2743: The literal type '10 | 11 | 12' cannot be modified. + + ++c + ~ +!!! error TS2743: The literal type '10 | 11 | 12' cannot be modified. + --c + ~ +!!! error TS2743: The literal type '10 | 11 | 12' cannot be modified. \ No newline at end of file diff --git a/tests/baselines/reference/numericLiteralTypes4.js b/tests/baselines/reference/numericLiteralTypes4.js new file mode 100644 index 0000000000000..9905ba84b7213 --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes4.js @@ -0,0 +1,105 @@ +//// [numericLiteralTypes4.ts] +var a: 10 = 10; +var b: 10 | 11 = 11; +var c: 10 | 11 | 12 = 10; + +a ++; +a --; +a += 1; +a -= 1; +a *= 1; +a /= 1; +a %= 1; +a &= 1; +a |= 1; +a ^= 1; +a >>= 1; +a >>>= 1; +a <<= 1; + +++a +--a + +b ++; +b --; +b += 1; +b -= 1; +b *= 1; +b /= 1; +b %= 1; +b &= 1; +b |= 1; +b ^= 1; +b >>= 1; +b >>>= 1; +b <<= 1; + +++b +--b + +c ++; +c --; +c += 1; +c -= 1; +c *= 1; +c /= 1; +c %= 1; +c &= 1; +c |= 1; +c ^= 1; +c >>= 1; +c >>>= 1; +c <<= 1; + +++c +--c + +//// [numericLiteralTypes4.js] +var a = 10; +var b = 11; +var c = 10; +a++; +a--; +a += 1; +a -= 1; +a *= 1; +a /= 1; +a %= 1; +a &= 1; +a |= 1; +a ^= 1; +a >>= 1; +a >>>= 1; +a <<= 1; +++a; +--a; +b++; +b--; +b += 1; +b -= 1; +b *= 1; +b /= 1; +b %= 1; +b &= 1; +b |= 1; +b ^= 1; +b >>= 1; +b >>>= 1; +b <<= 1; +++b; +--b; +c++; +c--; +c += 1; +c -= 1; +c *= 1; +c /= 1; +c %= 1; +c &= 1; +c |= 1; +c ^= 1; +c >>= 1; +c >>>= 1; +c <<= 1; +++c; +--c; diff --git a/tests/baselines/reference/numericLiteralTypes4.symbols b/tests/baselines/reference/numericLiteralTypes4.symbols new file mode 100644 index 0000000000000..5a3fc674ab44b --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes4.symbols @@ -0,0 +1,145 @@ +=== tests/cases/conformance/types/literal/numericLiteralTypes4.ts === +var a: 10 = 10; +>a : Symbol(a, Decl(numericLiteralTypes4.ts, 0, 3)) + +var b: 10 | 11 = 11; +>b : Symbol(b, Decl(numericLiteralTypes4.ts, 1, 3)) + +var c: 10 | 11 | 12 = 10; +>c : Symbol(c, Decl(numericLiteralTypes4.ts, 2, 3)) + +a ++; +>a : Symbol(a, Decl(numericLiteralTypes4.ts, 0, 3)) + +a --; +>a : Symbol(a, Decl(numericLiteralTypes4.ts, 0, 3)) + +a += 1; +>a : Symbol(a, Decl(numericLiteralTypes4.ts, 0, 3)) + +a -= 1; +>a : Symbol(a, Decl(numericLiteralTypes4.ts, 0, 3)) + +a *= 1; +>a : Symbol(a, Decl(numericLiteralTypes4.ts, 0, 3)) + +a /= 1; +>a : Symbol(a, Decl(numericLiteralTypes4.ts, 0, 3)) + +a %= 1; +>a : Symbol(a, Decl(numericLiteralTypes4.ts, 0, 3)) + +a &= 1; +>a : Symbol(a, Decl(numericLiteralTypes4.ts, 0, 3)) + +a |= 1; +>a : Symbol(a, Decl(numericLiteralTypes4.ts, 0, 3)) + +a ^= 1; +>a : Symbol(a, Decl(numericLiteralTypes4.ts, 0, 3)) + +a >>= 1; +>a : Symbol(a, Decl(numericLiteralTypes4.ts, 0, 3)) + +a >>>= 1; +>a : Symbol(a, Decl(numericLiteralTypes4.ts, 0, 3)) + +a <<= 1; +>a : Symbol(a, Decl(numericLiteralTypes4.ts, 0, 3)) + +++a +>a : Symbol(a, Decl(numericLiteralTypes4.ts, 0, 3)) + +--a +>a : Symbol(a, Decl(numericLiteralTypes4.ts, 0, 3)) + +b ++; +>b : Symbol(b, Decl(numericLiteralTypes4.ts, 1, 3)) + +b --; +>b : Symbol(b, Decl(numericLiteralTypes4.ts, 1, 3)) + +b += 1; +>b : Symbol(b, Decl(numericLiteralTypes4.ts, 1, 3)) + +b -= 1; +>b : Symbol(b, Decl(numericLiteralTypes4.ts, 1, 3)) + +b *= 1; +>b : Symbol(b, Decl(numericLiteralTypes4.ts, 1, 3)) + +b /= 1; +>b : Symbol(b, Decl(numericLiteralTypes4.ts, 1, 3)) + +b %= 1; +>b : Symbol(b, Decl(numericLiteralTypes4.ts, 1, 3)) + +b &= 1; +>b : Symbol(b, Decl(numericLiteralTypes4.ts, 1, 3)) + +b |= 1; +>b : Symbol(b, Decl(numericLiteralTypes4.ts, 1, 3)) + +b ^= 1; +>b : Symbol(b, Decl(numericLiteralTypes4.ts, 1, 3)) + +b >>= 1; +>b : Symbol(b, Decl(numericLiteralTypes4.ts, 1, 3)) + +b >>>= 1; +>b : Symbol(b, Decl(numericLiteralTypes4.ts, 1, 3)) + +b <<= 1; +>b : Symbol(b, Decl(numericLiteralTypes4.ts, 1, 3)) + +++b +>b : Symbol(b, Decl(numericLiteralTypes4.ts, 1, 3)) + +--b +>b : Symbol(b, Decl(numericLiteralTypes4.ts, 1, 3)) + +c ++; +>c : Symbol(c, Decl(numericLiteralTypes4.ts, 2, 3)) + +c --; +>c : Symbol(c, Decl(numericLiteralTypes4.ts, 2, 3)) + +c += 1; +>c : Symbol(c, Decl(numericLiteralTypes4.ts, 2, 3)) + +c -= 1; +>c : Symbol(c, Decl(numericLiteralTypes4.ts, 2, 3)) + +c *= 1; +>c : Symbol(c, Decl(numericLiteralTypes4.ts, 2, 3)) + +c /= 1; +>c : Symbol(c, Decl(numericLiteralTypes4.ts, 2, 3)) + +c %= 1; +>c : Symbol(c, Decl(numericLiteralTypes4.ts, 2, 3)) + +c &= 1; +>c : Symbol(c, Decl(numericLiteralTypes4.ts, 2, 3)) + +c |= 1; +>c : Symbol(c, Decl(numericLiteralTypes4.ts, 2, 3)) + +c ^= 1; +>c : Symbol(c, Decl(numericLiteralTypes4.ts, 2, 3)) + +c >>= 1; +>c : Symbol(c, Decl(numericLiteralTypes4.ts, 2, 3)) + +c >>>= 1; +>c : Symbol(c, Decl(numericLiteralTypes4.ts, 2, 3)) + +c <<= 1; +>c : Symbol(c, Decl(numericLiteralTypes4.ts, 2, 3)) + +++c +>c : Symbol(c, Decl(numericLiteralTypes4.ts, 2, 3)) + +--c +>c : Symbol(c, Decl(numericLiteralTypes4.ts, 2, 3)) + diff --git a/tests/baselines/reference/numericLiteralTypes4.types b/tests/baselines/reference/numericLiteralTypes4.types new file mode 100644 index 0000000000000..45a76e2d73a3c --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes4.types @@ -0,0 +1,226 @@ +=== tests/cases/conformance/types/literal/numericLiteralTypes4.ts === +var a: 10 = 10; +>a : 10 +>10 : 10 + +var b: 10 | 11 = 11; +>b : 10 | 11 +>11 : 11 + +var c: 10 | 11 | 12 = 10; +>c : 10 | 11 | 12 +>10 : 10 + +a ++; +>a ++ : number +>a : number + +a --; +>a -- : number +>a : number + +a += 1; +>a += 1 : number +>a : number +>1 : 1 + +a -= 1; +>a -= 1 : number +>a : number +>1 : 1 + +a *= 1; +>a *= 1 : number +>a : number +>1 : 1 + +a /= 1; +>a /= 1 : number +>a : number +>1 : 1 + +a %= 1; +>a %= 1 : number +>a : number +>1 : 1 + +a &= 1; +>a &= 1 : number +>a : number +>1 : 1 + +a |= 1; +>a |= 1 : number +>a : number +>1 : 1 + +a ^= 1; +>a ^= 1 : number +>a : number +>1 : 1 + +a >>= 1; +>a >>= 1 : number +>a : number +>1 : 1 + +a >>>= 1; +>a >>>= 1 : number +>a : number +>1 : 1 + +a <<= 1; +>a <<= 1 : number +>a : number +>1 : 1 + +++a +>++a : number +>a : number + +--a +>--a : number +>a : number + +b ++; +>b ++ : number +>b : number + +b --; +>b -- : number +>b : number + +b += 1; +>b += 1 : number +>b : number +>1 : 1 + +b -= 1; +>b -= 1 : number +>b : number +>1 : 1 + +b *= 1; +>b *= 1 : number +>b : number +>1 : 1 + +b /= 1; +>b /= 1 : number +>b : number +>1 : 1 + +b %= 1; +>b %= 1 : number +>b : number +>1 : 1 + +b &= 1; +>b &= 1 : number +>b : number +>1 : 1 + +b |= 1; +>b |= 1 : number +>b : number +>1 : 1 + +b ^= 1; +>b ^= 1 : number +>b : number +>1 : 1 + +b >>= 1; +>b >>= 1 : number +>b : number +>1 : 1 + +b >>>= 1; +>b >>>= 1 : number +>b : number +>1 : 1 + +b <<= 1; +>b <<= 1 : number +>b : number +>1 : 1 + +++b +>++b : number +>b : number + +--b +>--b : number +>b : number + +c ++; +>c ++ : number +>c : number + +c --; +>c -- : number +>c : number + +c += 1; +>c += 1 : number +>c : number +>1 : 1 + +c -= 1; +>c -= 1 : number +>c : number +>1 : 1 + +c *= 1; +>c *= 1 : number +>c : number +>1 : 1 + +c /= 1; +>c /= 1 : number +>c : number +>1 : 1 + +c %= 1; +>c %= 1 : number +>c : number +>1 : 1 + +c &= 1; +>c &= 1 : number +>c : number +>1 : 1 + +c |= 1; +>c |= 1 : number +>c : number +>1 : 1 + +c ^= 1; +>c ^= 1 : number +>c : number +>1 : 1 + +c >>= 1; +>c >>= 1 : number +>c : number +>1 : 1 + +c >>>= 1; +>c >>>= 1 : number +>c : number +>1 : 1 + +c <<= 1; +>c <<= 1 : number +>c : number +>1 : 1 + +++c +>++c : number +>c : number + +--c +>--c : number +>c : number + diff --git a/tests/baselines/reference/stringLiteralTypes4.errors.txt b/tests/baselines/reference/stringLiteralTypes4.errors.txt new file mode 100644 index 0000000000000..21b24a7e0b6a7 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypes4.errors.txt @@ -0,0 +1,8 @@ +tests/cases/conformance/types/literal/stringLiteralTypes4.ts(2,1): error TS2743: The literal type '"foo" | "bar"' cannot be modified. + + +==== tests/cases/conformance/types/literal/stringLiteralTypes4.ts (1 errors) ==== + var s: 'foo' | 'bar' = 'bar'; + s += 'bar'; + ~ +!!! error TS2743: The literal type '"foo" | "bar"' cannot be modified. \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypes4.js b/tests/baselines/reference/stringLiteralTypes4.js new file mode 100644 index 0000000000000..2711ae303d618 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypes4.js @@ -0,0 +1,7 @@ +//// [stringLiteralTypes4.ts] +var s: 'foo' | 'bar' = 'bar'; +s += 'bar'; + +//// [stringLiteralTypes4.js] +var s = 'bar'; +s += 'bar'; diff --git a/tests/baselines/reference/stringLiteralTypes4.symbols b/tests/baselines/reference/stringLiteralTypes4.symbols new file mode 100644 index 0000000000000..dcab7e0b76e63 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypes4.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/types/literal/stringLiteralTypes4.ts === +var s: 'foo' | 'bar' = 'bar'; +>s : Symbol(s, Decl(stringLiteralTypes4.ts, 0, 3)) + +s += 'bar'; +>s : Symbol(s, Decl(stringLiteralTypes4.ts, 0, 3)) + diff --git a/tests/baselines/reference/stringLiteralTypes4.types b/tests/baselines/reference/stringLiteralTypes4.types new file mode 100644 index 0000000000000..0264cea747ddc --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypes4.types @@ -0,0 +1,10 @@ +=== tests/cases/conformance/types/literal/stringLiteralTypes4.ts === +var s: 'foo' | 'bar' = 'bar'; +>s : "foo" | "bar" +>'bar' : "bar" + +s += 'bar'; +>s += 'bar' : string +>s : string +>'bar' : "bar" + diff --git a/tests/cases/conformance/types/literal/literalTypeProperty.ts b/tests/cases/conformance/types/literal/literalTypeProperty.ts new file mode 100644 index 0000000000000..05dac682792c1 --- /dev/null +++ b/tests/cases/conformance/types/literal/literalTypeProperty.ts @@ -0,0 +1,19 @@ +declare class C { + foo: 10; + bar: 10 | 11 +} + +var o = new C() +o.foo ++ +o.foo += 1 +o.foo -= 1 +o.foo -- +++o.foo +--o.foo + +o.bar ++ +o.bar += 1 +o.bar -= 1 +o.bar -- +++o.bar +--o.bar \ No newline at end of file diff --git a/tests/cases/conformance/types/literal/numericLiteralTypes4.ts b/tests/cases/conformance/types/literal/numericLiteralTypes4.ts new file mode 100644 index 0000000000000..c737907545ada --- /dev/null +++ b/tests/cases/conformance/types/literal/numericLiteralTypes4.ts @@ -0,0 +1,54 @@ +var a: 10 = 10; +var b: 10 | 11 = 11; +var c: 10 | 11 | 12 = 10; + +a ++; +a --; +a += 1; +a -= 1; +a *= 1; +a /= 1; +a %= 1; +a &= 1; +a |= 1; +a ^= 1; +a >>= 1; +a >>>= 1; +a <<= 1; + +++a +--a + +b ++; +b --; +b += 1; +b -= 1; +b *= 1; +b /= 1; +b %= 1; +b &= 1; +b |= 1; +b ^= 1; +b >>= 1; +b >>>= 1; +b <<= 1; + +++b +--b + +c ++; +c --; +c += 1; +c -= 1; +c *= 1; +c /= 1; +c %= 1; +c &= 1; +c |= 1; +c ^= 1; +c >>= 1; +c >>>= 1; +c <<= 1; + +++c +--c \ No newline at end of file diff --git a/tests/cases/conformance/types/literal/stringLiteralTypes4.ts b/tests/cases/conformance/types/literal/stringLiteralTypes4.ts new file mode 100644 index 0000000000000..e42eede5e4857 --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralTypes4.ts @@ -0,0 +1,2 @@ +var s: 'foo' | 'bar' = 'bar'; +s += 'bar'; \ No newline at end of file