a515b199b7
Fixes #93. This is an evolution of #220.
52 lines
No EOL
1.4 KiB
Text
52 lines
No EOL
1.4 KiB
Text
==== tests/cases/compiler/assignmentCompatability_checking-call-member-off-of-function-interface.ts (8 errors) ====
|
|
// 3.8.4 Assignment Compatibility
|
|
|
|
interface Callable {
|
|
call(blah: any); // also works for 'apply'
|
|
}
|
|
|
|
var x: Callable;
|
|
|
|
// Should fail
|
|
x = '';
|
|
~
|
|
!!! Type 'string' is not assignable to type 'Callable':
|
|
!!! Property 'call' is missing in type 'String'.
|
|
x = [''];
|
|
~
|
|
!!! Type 'string[]' is not assignable to type 'Callable':
|
|
!!! Property 'call' is missing in type 'string[]'.
|
|
x = 4;
|
|
~
|
|
!!! Type 'number' is not assignable to type 'Callable':
|
|
!!! Property 'call' is missing in type 'Number'.
|
|
x = {};
|
|
~
|
|
!!! Type '{}' is not assignable to type 'Callable':
|
|
!!! Property 'call' is missing in type '{}'.
|
|
|
|
// Should work
|
|
function f() { };
|
|
x = f;
|
|
|
|
function fn(c: Callable) { }
|
|
|
|
// Should Fail
|
|
fn('');
|
|
~~
|
|
!!! Argument type 'string' is not assignable to parameter type 'Callable'.
|
|
fn(['']);
|
|
~~~~
|
|
!!! Argument type 'string[]' is not assignable to parameter type 'Callable'.
|
|
fn(4);
|
|
~
|
|
!!! Argument type 'number' is not assignable to parameter type 'Callable'.
|
|
fn({});
|
|
~~
|
|
!!! Argument type '{}' is not assignable to parameter type 'Callable'.
|
|
!!! Property 'call' is missing in type '{}'.
|
|
|
|
|
|
// Should work
|
|
fn(a => { });
|
|
|