25 lines
No EOL
1.3 KiB
Text
25 lines
No EOL
1.3 KiB
Text
==== tests/cases/compiler/objectLiteralFunctionArgContextualTyping.ts (4 errors) ====
|
|
interface I {
|
|
value: string;
|
|
toString: (t: string) => string;
|
|
}
|
|
|
|
function f2(args: I) { }
|
|
|
|
f2({ hello: 1 }) // error
|
|
~~~~~~~~~~~~
|
|
!!! Argument of type '{ hello: number; }' is not assignable to parameter of type 'I'.
|
|
!!! Property 'value' is missing in type '{ hello: number; }'.
|
|
f2({ value: '' }) // missing toString satisfied by Object's member
|
|
f2({ value: '', what: 1 }) // missing toString satisfied by Object's member
|
|
f2({ toString: (s) => s }) // error, missing property value from ArgsString
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
|
!!! Argument of type '{ toString: (s: string) => string; }' is not assignable to parameter of type 'I'.
|
|
!!! Property 'value' is missing in type '{ toString: (s: string) => string; }'.
|
|
f2({ toString: (s: string) => s }) // error, missing property value from ArgsString
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
!!! Argument of type '{ toString: (s: string) => string; }' is not assignable to parameter of type 'I'.
|
|
!!! Property 'value' is missing in type '{ toString: (s: string) => string; }'.
|
|
f2({ value: '', toString: (s) => s.uhhh }) // error
|
|
~~~~
|
|
!!! Property 'uhhh' does not exist on type 'string'. |