File: contravariantOnlyInferenceFromAnnotatedFunction.types

package info (click to toggle)
node-typescript 5.1.6%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 492,516 kB
  • sloc: javascript: 2,078,951; makefile: 6; sh: 1
file content (44 lines) | stat: -rw-r--r-- 1,196 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
34
35
36
37
38
39
40
41
42
43
44
=== tests/cases/compiler/contravariantOnlyInferenceFromAnnotatedFunction.ts ===
// repro from #52580

type Funcs<A, B extends Record<string, unknown>> = {
>Funcs : Funcs<A, B>

  [K in keyof B]: {
    fn: (a: A, b: B) => void;
>fn : (a: A, b: B) => void
>a : A
>b : B

    thing: B[K];
>thing : B[K]

  };
}

declare function foo<A, B extends Record<string, unknown>>(fns: Funcs<A, B>): [A, B]
>foo : <A, B extends Record<string, unknown>>(fns: Funcs<A, B>) => [A, B]
>fns : Funcs<A, B>

const result = foo({
>result : [string, { bar: string; }]
>foo({  bar: {    fn: (a: string) => {},    thing: 'asd',  },}) : [string, { bar: string; }]
>foo : <A, B extends Record<string, unknown>>(fns: Funcs<A, B>) => [A, B]
>{  bar: {    fn: (a: string) => {},    thing: 'asd',  },} : { bar: { fn: (a: string) => void; thing: string; }; }

  bar: {
>bar : { fn: (a: string) => void; thing: string; }
>{    fn: (a: string) => {},    thing: 'asd',  } : { fn: (a: string) => void; thing: string; }

    fn: (a: string) => {},
>fn : (a: string) => void
>(a: string) => {} : (a: string) => void
>a : string

    thing: 'asd',
>thing : string
>'asd' : "asd"

  },
});