Added some tests for overload compatibility.
This commit is contained in:
parent
2c2b8be238
commit
820a2cb257
12
tests/cases/compiler/functionOverloads43.ts
Normal file
12
tests/cases/compiler/functionOverloads43.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
function foo(bar: { a:number }[]): number;
|
||||
function foo(bar: { a:string }[]): string;
|
||||
function foo([x]: { a:number | string }[]): string | number {
|
||||
if (x) {
|
||||
return x.a;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var x = foo([{a: "str"}]);
|
||||
var y = foo([{a: 100}]);
|
22
tests/cases/compiler/functionOverloads44.ts
Normal file
22
tests/cases/compiler/functionOverloads44.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
interface Animal { animal }
|
||||
interface Dog extends Animal { dog }
|
||||
interface Cat extends Animal { cat }
|
||||
|
||||
function foo1(bar: { a:number }[]): Dog;
|
||||
function foo1(bar: { a:string }[]): Animal;
|
||||
function foo1([x]: { a:number | string }[]): Dog {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function foo2(bar: { a:number }[]): Cat;
|
||||
function foo2(bar: { a:string }[]): Cat | Dog;
|
||||
function foo2([x]: { a:number | string }[]): Cat {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
var x1 = foo1([{a: "str"}]);
|
||||
var y1 = foo1([{a: 100}]);
|
||||
|
||||
var x2 = foo2([{a: "str"}]);
|
||||
var y2 = foo2([{a: 100}]);
|
22
tests/cases/compiler/functionOverloads45.ts
Normal file
22
tests/cases/compiler/functionOverloads45.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
interface Animal { animal }
|
||||
interface Dog extends Animal { dog }
|
||||
interface Cat extends Animal { cat }
|
||||
|
||||
function foo1(bar: { a:number }[]): Cat;
|
||||
function foo1(bar: { a:string }[]): Dog;
|
||||
function foo1([x]: { a:number | string }[]): Animal {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function foo2(bar: { a:number }[]): Cat;
|
||||
function foo2(bar: { a:string }[]): Dog;
|
||||
function foo2([x]: { a:number | string }[]): Cat | Dog {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
var x1 = foo1([{a: "str"}]);
|
||||
var y1 = foo1([{a: 100}]);
|
||||
|
||||
var x2 = foo2([{a: "str"}]);
|
||||
var y2 = foo2([{a: 100}]);
|
Loading…
Reference in a new issue