mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 10:29:18 -05:00
Add tests for object literals with computed properties
This commit is contained in:
35
tests/baselines/reference/computedPropertyNames4.js
Normal file
35
tests/baselines/reference/computedPropertyNames4.js
Normal file
@@ -0,0 +1,35 @@
|
||||
//// [computedPropertyNames4.ts]
|
||||
var s: string;
|
||||
var n: number;
|
||||
var a: any;
|
||||
var v = {
|
||||
[s]: 0,
|
||||
[n]: n,
|
||||
[s + s]: 1,
|
||||
[s + n]: 2,
|
||||
[+s]: s,
|
||||
[""]: 0,
|
||||
[0]: 0,
|
||||
[a]: 1,
|
||||
[<any>true]: 0,
|
||||
[`hello bye`]: 0,
|
||||
[`hello ${a} bye`]: 0
|
||||
}
|
||||
|
||||
//// [computedPropertyNames4.js]
|
||||
var s;
|
||||
var n;
|
||||
var a;
|
||||
var v = {
|
||||
[s]: 0,
|
||||
[n]: n,
|
||||
[s + s]: 1,
|
||||
[s + n]: 2,
|
||||
[+s]: s,
|
||||
[""]: 0,
|
||||
[0]: 0,
|
||||
[a]: 1,
|
||||
[true]: 0,
|
||||
[`hello bye`]: 0,
|
||||
[`hello ${a} bye`]: 0
|
||||
};
|
||||
48
tests/baselines/reference/computedPropertyNames4.types
Normal file
48
tests/baselines/reference/computedPropertyNames4.types
Normal file
@@ -0,0 +1,48 @@
|
||||
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames4.ts ===
|
||||
var s: string;
|
||||
>s : string
|
||||
|
||||
var n: number;
|
||||
>n : number
|
||||
|
||||
var a: any;
|
||||
>a : any
|
||||
|
||||
var v = {
|
||||
>v : {}
|
||||
>{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [<any>true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : {}
|
||||
|
||||
[s]: 0,
|
||||
>s : string
|
||||
|
||||
[n]: n,
|
||||
>n : number
|
||||
>n : number
|
||||
|
||||
[s + s]: 1,
|
||||
>s + s : string
|
||||
>s : string
|
||||
>s : string
|
||||
|
||||
[s + n]: 2,
|
||||
>s + n : string
|
||||
>s : string
|
||||
>n : number
|
||||
|
||||
[+s]: s,
|
||||
>+s : number
|
||||
>s : string
|
||||
>s : string
|
||||
|
||||
[""]: 0,
|
||||
[0]: 0,
|
||||
[a]: 1,
|
||||
>a : any
|
||||
|
||||
[<any>true]: 0,
|
||||
><any>true : any
|
||||
|
||||
[`hello bye`]: 0,
|
||||
[`hello ${a} bye`]: 0
|
||||
>a : any
|
||||
}
|
||||
30
tests/baselines/reference/computedPropertyNames5.errors.txt
Normal file
30
tests/baselines/reference/computedPropertyNames5.errors.txt
Normal file
@@ -0,0 +1,30 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(3,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(4,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(5,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(6,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(7,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts(8,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames5.ts (6 errors) ====
|
||||
var b: boolean;
|
||||
var v = {
|
||||
[b]: 0,
|
||||
~~~
|
||||
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
[true]: 1,
|
||||
~~~~~~
|
||||
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
[[]]: 0,
|
||||
~~~~
|
||||
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
[{}]: 0,
|
||||
~~~~
|
||||
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
[undefined]: undefined,
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
[null]: null
|
||||
~~~~~~
|
||||
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
}
|
||||
21
tests/baselines/reference/computedPropertyNames5.js
Normal file
21
tests/baselines/reference/computedPropertyNames5.js
Normal file
@@ -0,0 +1,21 @@
|
||||
//// [computedPropertyNames5.ts]
|
||||
var b: boolean;
|
||||
var v = {
|
||||
[b]: 0,
|
||||
[true]: 1,
|
||||
[[]]: 0,
|
||||
[{}]: 0,
|
||||
[undefined]: undefined,
|
||||
[null]: null
|
||||
}
|
||||
|
||||
//// [computedPropertyNames5.js]
|
||||
var b;
|
||||
var v = {
|
||||
[b]: 0,
|
||||
[true]: 1,
|
||||
[[]]: 0,
|
||||
[{}]: 0,
|
||||
[undefined]: undefined,
|
||||
[null]: null
|
||||
};
|
||||
20
tests/baselines/reference/computedPropertyNames6.errors.txt
Normal file
20
tests/baselines/reference/computedPropertyNames6.errors.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(5,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(6,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts(7,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames6.ts (3 errors) ====
|
||||
var p1: number | string;
|
||||
var p2: number | number[];
|
||||
var p3: string | boolean;
|
||||
var v = {
|
||||
[p1]: 0,
|
||||
~~~~
|
||||
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
[p2]: 1,
|
||||
~~~~
|
||||
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
[p3]: 2
|
||||
~~~~
|
||||
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
}
|
||||
19
tests/baselines/reference/computedPropertyNames6.js
Normal file
19
tests/baselines/reference/computedPropertyNames6.js
Normal file
@@ -0,0 +1,19 @@
|
||||
//// [computedPropertyNames6.ts]
|
||||
var p1: number | string;
|
||||
var p2: number | number[];
|
||||
var p3: string | boolean;
|
||||
var v = {
|
||||
[p1]: 0,
|
||||
[p2]: 1,
|
||||
[p3]: 2
|
||||
}
|
||||
|
||||
//// [computedPropertyNames6.js]
|
||||
var p1;
|
||||
var p2;
|
||||
var p3;
|
||||
var v = {
|
||||
[p1]: 0,
|
||||
[p2]: 1,
|
||||
[p3]: 2
|
||||
};
|
||||
12
tests/baselines/reference/computedPropertyNames7.errors.txt
Normal file
12
tests/baselines/reference/computedPropertyNames7.errors.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames7.ts(5,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames7.ts (1 errors) ====
|
||||
enum E {
|
||||
member
|
||||
}
|
||||
var v = {
|
||||
[E.member]: 0
|
||||
~~~~~~~~~~
|
||||
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
}
|
||||
16
tests/baselines/reference/computedPropertyNames7.js
Normal file
16
tests/baselines/reference/computedPropertyNames7.js
Normal file
@@ -0,0 +1,16 @@
|
||||
//// [computedPropertyNames7.ts]
|
||||
enum E {
|
||||
member
|
||||
}
|
||||
var v = {
|
||||
[E.member]: 0
|
||||
}
|
||||
|
||||
//// [computedPropertyNames7.js]
|
||||
var E;
|
||||
(function (E) {
|
||||
E[E["member"] = 0] = "member";
|
||||
})(E || (E = {}));
|
||||
var v = {
|
||||
[0 /* member */]: 0
|
||||
};
|
||||
17
tests/baselines/reference/computedPropertyNames8.errors.txt
Normal file
17
tests/baselines/reference/computedPropertyNames8.errors.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts(5,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts(6,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames8.ts (2 errors) ====
|
||||
function f<T, U extends string>() {
|
||||
var t: T;
|
||||
var u: U;
|
||||
var v = {
|
||||
[t]: 0,
|
||||
~~~
|
||||
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
[u]: 1
|
||||
~~~
|
||||
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
};
|
||||
}
|
||||
19
tests/baselines/reference/computedPropertyNames8.js
Normal file
19
tests/baselines/reference/computedPropertyNames8.js
Normal file
@@ -0,0 +1,19 @@
|
||||
//// [computedPropertyNames8.ts]
|
||||
function f<T, U extends string>() {
|
||||
var t: T;
|
||||
var u: U;
|
||||
var v = {
|
||||
[t]: 0,
|
||||
[u]: 1
|
||||
};
|
||||
}
|
||||
|
||||
//// [computedPropertyNames8.js]
|
||||
function f() {
|
||||
var t;
|
||||
var u;
|
||||
var v = {
|
||||
[t]: 0,
|
||||
[u]: 1
|
||||
};
|
||||
}
|
||||
16
tests/baselines/reference/computedPropertyNames9.errors.txt
Normal file
16
tests/baselines/reference/computedPropertyNames9.errors.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames9.ts(9,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames9.ts (1 errors) ====
|
||||
function f(s: string): string;
|
||||
function f(n: number): number;
|
||||
function f<T>(x: T): T;
|
||||
function f(x): any { }
|
||||
|
||||
var v = {
|
||||
[f("")]: 0,
|
||||
[f(0)]: 0,
|
||||
[f(true)]: 0
|
||||
~~~~~~~~~
|
||||
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
}
|
||||
20
tests/baselines/reference/computedPropertyNames9.js
Normal file
20
tests/baselines/reference/computedPropertyNames9.js
Normal file
@@ -0,0 +1,20 @@
|
||||
//// [computedPropertyNames9.ts]
|
||||
function f(s: string): string;
|
||||
function f(n: number): number;
|
||||
function f<T>(x: T): T;
|
||||
function f(x): any { }
|
||||
|
||||
var v = {
|
||||
[f("")]: 0,
|
||||
[f(0)]: 0,
|
||||
[f(true)]: 0
|
||||
}
|
||||
|
||||
//// [computedPropertyNames9.js]
|
||||
function f(x) {
|
||||
}
|
||||
var v = {
|
||||
[f("")]: 0,
|
||||
[f(0)]: 0,
|
||||
[f(true)]: 0
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
// @target: es6
|
||||
var s: string;
|
||||
var n: number;
|
||||
var a: any;
|
||||
var v = {
|
||||
[s]: 0,
|
||||
[n]: n,
|
||||
[s + s]: 1,
|
||||
[s + n]: 2,
|
||||
[+s]: s,
|
||||
[""]: 0,
|
||||
[0]: 0,
|
||||
[a]: 1,
|
||||
[<any>true]: 0,
|
||||
[`hello bye`]: 0,
|
||||
[`hello ${a} bye`]: 0
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// @target: es6
|
||||
var b: boolean;
|
||||
var v = {
|
||||
[b]: 0,
|
||||
[true]: 1,
|
||||
[[]]: 0,
|
||||
[{}]: 0,
|
||||
[undefined]: undefined,
|
||||
[null]: null
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// @target: es6
|
||||
var p1: number | string;
|
||||
var p2: number | number[];
|
||||
var p3: string | boolean;
|
||||
var v = {
|
||||
[p1]: 0,
|
||||
[p2]: 1,
|
||||
[p3]: 2
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// @target: es6
|
||||
enum E {
|
||||
member
|
||||
}
|
||||
var v = {
|
||||
[E.member]: 0
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// @target: es6
|
||||
function f<T, U extends string>() {
|
||||
var t: T;
|
||||
var u: U;
|
||||
var v = {
|
||||
[t]: 0,
|
||||
[u]: 1
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// @target: es6
|
||||
function f(s: string): string;
|
||||
function f(n: number): number;
|
||||
function f<T>(x: T): T;
|
||||
function f(x): any { }
|
||||
|
||||
var v = {
|
||||
[f("")]: 0,
|
||||
[f(0)]: 0,
|
||||
[f(true)]: 0
|
||||
}
|
||||
Reference in New Issue
Block a user