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