Skip to content

Commit

Permalink
Merge pull request #822 from Microsoft/tupleConformance
Browse files Browse the repository at this point in the history
Tuple conformance
  • Loading branch information
Yui committed Oct 6, 2014
2 parents 432fff1 + 0ef3cd1 commit 85fd141
Show file tree
Hide file tree
Showing 24 changed files with 1,137 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(17,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]':
Types of property 'pop' are incompatible:
Type '() => {}' is not assignable to type '() => number':
Type '{}' is not assignable to type 'number'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(18,1): error TS2322: Type '{}[]' is not assignable to type '[{}]':
Property '0' is missing in type '{}[]'.


==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts (2 errors) ====
var numStrTuple: [number, string];
var numNumTuple: [number, number];
var numEmptyObjTuple: [number, {}];
var emptyObjTuple: [{}];

var numArray: number[];
var emptyObjArray: {}[];

// no error
numArray = numNumTuple;
emptyObjArray = emptyObjTuple;
emptyObjArray = numStrTuple;
emptyObjArray = numNumTuple;
emptyObjArray = numEmptyObjTuple;

// error
numArray = numStrTuple;
~~~~~~~~
!!! error TS2322: Type '[number, string]' is not assignable to type 'number[]':
!!! error TS2322: Types of property 'pop' are incompatible:
!!! error TS2322: Type '() => {}' is not assignable to type '() => number':
!!! error TS2322: Type '{}' is not assignable to type 'number'.
emptyObjTuple = emptyObjArray;
~~~~~~~~~~~~~
!!! error TS2322: Type '{}[]' is not assignable to type '[{}]':
!!! error TS2322: Property '0' is missing in type '{}[]'.

37 changes: 37 additions & 0 deletions tests/baselines/reference/assignmentCompatBetweenTupleAndArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//// [assignmentCompatBetweenTupleAndArray.ts]
var numStrTuple: [number, string];
var numNumTuple: [number, number];
var numEmptyObjTuple: [number, {}];
var emptyObjTuple: [{}];

var numArray: number[];
var emptyObjArray: {}[];

// no error
numArray = numNumTuple;
emptyObjArray = emptyObjTuple;
emptyObjArray = numStrTuple;
emptyObjArray = numNumTuple;
emptyObjArray = numEmptyObjTuple;

// error
numArray = numStrTuple;
emptyObjTuple = emptyObjArray;


//// [assignmentCompatBetweenTupleAndArray.js]
var numStrTuple;
var numNumTuple;
var numEmptyObjTuple;
var emptyObjTuple;
var numArray;
var emptyObjArray;
// no error
numArray = numNumTuple;
emptyObjArray = emptyObjTuple;
emptyObjArray = numStrTuple;
emptyObjArray = numNumTuple;
emptyObjArray = numEmptyObjTuple;
// error
numArray = numStrTuple;
emptyObjTuple = emptyObjArray;
58 changes: 58 additions & 0 deletions tests/baselines/reference/bestCommonTypeOfTuple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//// [bestCommonTypeOfTuple.ts]
function f1(x: number): string { return "foo"; }

function f2(x: number): number { return 10; }

function f3(x: number): boolean { return true; }

enum E1 { one }

enum E2 { two }


var t1: [(x: number) => string, (x: number) => number];
var t2: [E1, E2];
var t3: [number, any];
var t4: [E1, E2, number];

// no error
t1 = [f1, f2];
t2 = [E1.one, E2.two];
t3 = [5, undefined];
t4 = [E1.one, E2.two, 20];
var e1 = t1[2]; // {}
var e2 = t2[2]; // {}
var e3 = t3[2]; // any
var e4 = t4[3]; // number

//// [bestCommonTypeOfTuple.js]
function f1(x) {
return "foo";
}
function f2(x) {
return 10;
}
function f3(x) {
return true;
}
var E1;
(function (E1) {
E1[E1["one"] = 0] = "one";
})(E1 || (E1 = {}));
var E2;
(function (E2) {
E2[E2["two"] = 0] = "two";
})(E2 || (E2 = {}));
var t1;
var t2;
var t3;
var t4;
// no error
t1 = [f1, f2];
t2 = [0 /* one */, 0 /* two */];
t3 = [5, undefined];
t4 = [0 /* one */, 0 /* two */, 20];
var e1 = t1[2]; // {}
var e2 = t2[2]; // {}
var e3 = t3[2]; // any
var e4 = t4[3]; // number
96 changes: 96 additions & 0 deletions tests/baselines/reference/bestCommonTypeOfTuple.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
=== tests/cases/conformance/types/typeRelationships/bestCommonType/bestCommonTypeOfTuple.ts ===
function f1(x: number): string { return "foo"; }
>f1 : (x: number) => string
>x : number

function f2(x: number): number { return 10; }
>f2 : (x: number) => number
>x : number

function f3(x: number): boolean { return true; }
>f3 : (x: number) => boolean
>x : number

enum E1 { one }
>E1 : E1
>one : E1

enum E2 { two }
>E2 : E2
>two : E2


var t1: [(x: number) => string, (x: number) => number];
>t1 : [(x: number) => string, (x: number) => number]
>x : number
>x : number

var t2: [E1, E2];
>t2 : [E1, E2]
>E1 : E1
>E2 : E2

var t3: [number, any];
>t3 : [number, any]

var t4: [E1, E2, number];
>t4 : [E1, E2, number]
>E1 : E1
>E2 : E2

// no error
t1 = [f1, f2];
>t1 = [f1, f2] : [(x: number) => string, (x: number) => number]
>t1 : [(x: number) => string, (x: number) => number]
>[f1, f2] : [(x: number) => string, (x: number) => number]
>f1 : (x: number) => string
>f2 : (x: number) => number

t2 = [E1.one, E2.two];
>t2 = [E1.one, E2.two] : [E1, E2]
>t2 : [E1, E2]
>[E1.one, E2.two] : [E1, E2]
>E1.one : E1
>E1 : typeof E1
>one : E1
>E2.two : E2
>E2 : typeof E2
>two : E2

t3 = [5, undefined];
>t3 = [5, undefined] : [number, undefined]
>t3 : [number, any]
>[5, undefined] : [number, undefined]
>undefined : undefined

t4 = [E1.one, E2.two, 20];
>t4 = [E1.one, E2.two, 20] : [E1, E2, number]
>t4 : [E1, E2, number]
>[E1.one, E2.two, 20] : [E1, E2, number]
>E1.one : E1
>E1 : typeof E1
>one : E1
>E2.two : E2
>E2 : typeof E2
>two : E2

var e1 = t1[2]; // {}
>e1 : {}
>t1[2] : {}
>t1 : [(x: number) => string, (x: number) => number]

var e2 = t2[2]; // {}
>e2 : {}
>t2[2] : {}
>t2 : [E1, E2]

var e3 = t3[2]; // any
>e3 : any
>t3[2] : any
>t3 : [number, any]

var e4 = t4[3]; // number
>e4 : number
>t4[3] : number
>t4 : [E1, E2, number]

77 changes: 77 additions & 0 deletions tests/baselines/reference/bestCommonTypeOfTuple2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//// [bestCommonTypeOfTuple2.ts]
interface base { }
interface base1 { i }
class C implements base { c }
class D implements base { d }
class E implements base { e }
class F extends C { f }

class C1 implements base1 { i = "foo"; c }
class D1 extends C1 { i = "bar"; d }

var t1: [C, base];
var t2: [C, D];
var t3: [C1, D1];
var t4: [base1, C1];
var t5: [C1, F]

var e11 = t1[4]; // base
var e21 = t2[4]; // {}
var e31 = t3[4]; // C1
var e41 = t4[2]; // base1
var e51 = t5[2]; // {}


//// [bestCommonTypeOfTuple2.js]
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var C = (function () {
function C() {
}
return C;
})();
var D = (function () {
function D() {
}
return D;
})();
var E = (function () {
function E() {
}
return E;
})();
var F = (function (_super) {
__extends(F, _super);
function F() {
_super.apply(this, arguments);
}
return F;
})(C);
var C1 = (function () {
function C1() {
this.i = "foo";
}
return C1;
})();
var D1 = (function (_super) {
__extends(D1, _super);
function D1() {
_super.apply(this, arguments);
this.i = "bar";
}
return D1;
})(C1);
var t1;
var t2;
var t3;
var t4;
var t5;
var e11 = t1[4]; // base
var e21 = t2[4]; // {}
var e31 = t3[4]; // C1
var e41 = t4[2]; // base1
var e51 = t5[2]; // {}
Loading

0 comments on commit 85fd141

Please sign in to comment.