File: genericCallWithFunctionTypedArguments5.errors.txt

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (33 lines) | stat: -rw-r--r-- 2,089 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments5.ts(10,16): error TS2322: Type '<T>(x: T, y: T) => string' is not assignable to type '(t: {}) => string'.
tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments5.ts(11,16): error TS2322: Type '(x: string, y: number) => string' is not assignable to type '(t: string) => string'.


==== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments5.ts (2 errors) ====
    // Generic call with parameter of object type with member of function type of n args passed object whose associated member is call signature with n+1 args
    
    function foo<T, U>(arg: { cb: (t: T) => U }) {
        return arg.cb(null);
    }
    
    var arg = { cb: <T>(x: T) => '' };
    var r = foo(arg); // {}
    // more args not allowed
    var r2 = foo({ cb: <T>(x: T, y: T) => '' }); // error
                   ~~
!!! error TS2322: Type '<T>(x: T, y: T) => string' is not assignable to type '(t: {}) => string'.
!!! related TS6500 tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments5.ts:3:27: The expected type comes from property 'cb' which is declared here on type '{ cb: (t: {}) => string; }'
    var r3 = foo({ cb: (x: string, y: number) => '' }); // error
                   ~~
!!! error TS2322: Type '(x: string, y: number) => string' is not assignable to type '(t: string) => string'.
!!! related TS6500 tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithFunctionTypedArguments5.ts:3:27: The expected type comes from property 'cb' which is declared here on type '{ cb: (t: string) => string; }'
    
    function foo2<T, U>(arg: { cb: (t: T, t2: T) => U }) {
        return arg.cb(null, null);
    }
    
    // fewer args ok
    var r4 = foo(arg); // {}
    var r5 = foo({ cb: <T>(x: T) => '' }); // {}
    var r6 = foo({ cb: (x: string) => '' }); // string
    var r7 = foo({ cb: () => '' }); // string