39 lines
No EOL
1.7 KiB
Text
39 lines
No EOL
1.7 KiB
Text
==== tests/cases/compiler/overloadResolutionTest1.ts (3 errors) ====
|
|
|
|
function foo(bar:{a:number;}[]):string;
|
|
function foo(bar:{a:boolean;}[]):number;
|
|
function foo(bar:{a:any;}[]):any{ return bar };
|
|
|
|
var x1 = foo([{a:true}]); // works
|
|
var x11 = foo([{a:0}]); // works
|
|
var x111 = foo([{a:"s"}]); // error - does not match any signature
|
|
~~~~~~~~~
|
|
!!! Argument of type '{ a: string; }[]' is not assignable to parameter of type '{ a: boolean; }[]'.
|
|
!!! Type '{ a: string; }' is not assignable to type '{ a: boolean; }':
|
|
!!! Types of property 'a' are incompatible:
|
|
!!! Type 'string' is not assignable to type 'boolean'.
|
|
var x1111 = foo([{a:null}]); // works - ambiguous call is resolved to be the first in the overload set so this returns a string
|
|
|
|
|
|
|
|
function foo2(bar:{a:number;}):string;
|
|
function foo2(bar:{a:boolean;}):number;
|
|
function foo2(bar:{a:any;}):any{ return bar };
|
|
|
|
var x2 = foo2({a:0}); // works
|
|
var x3 = foo2({a:true}); // works
|
|
var x4 = foo2({a:"s"}); // error
|
|
~~~~~~~
|
|
!!! Argument of type '{ a: string; }' is not assignable to parameter of type '{ a: boolean; }'.
|
|
!!! Types of property 'a' are incompatible:
|
|
!!! Type 'string' is not assignable to type 'boolean'.
|
|
|
|
|
|
function foo4(bar:{a:number;}):number;
|
|
function foo4(bar:{a:string;}):string;
|
|
function foo4(bar:{a:any;}):any{ return bar };
|
|
var x = foo4({a:true}); // error
|
|
~~~~~~~~
|
|
!!! Argument of type '{ a: boolean; }' is not assignable to parameter of type '{ a: string; }'.
|
|
!!! Types of property 'a' are incompatible:
|
|
!!! Type 'boolean' is not assignable to type 'string'. |