File: indexedAccessRelation.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (35 lines) | stat: -rw-r--r-- 1,468 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
tests/cases/compiler/indexedAccessRelation.ts(16,23): error TS2345: Argument of type '{ a: T; }' is not assignable to parameter of type 'Pick<S & State<T>, "a">'.
  Types of property 'a' are incompatible.
    Type 'T' is not assignable to type 'S["a"] & T'.
      Type 'Foo' is not assignable to type 'S["a"] & T'.
        Type 'Foo' is not assignable to type 'S["a"]'.
          'S["a"]' could be instantiated with an arbitrary type which could be unrelated to 'Foo'.


==== tests/cases/compiler/indexedAccessRelation.ts (1 errors) ====
    // Repro from #14723
    
    class Component<S> {
        setState<K extends keyof S>(state: Pick<S, K>) {}
    }
    
    export interface State<T> {
        a?: T;
    }
    
    class Foo {}
    
    class Comp<T extends Foo, S> extends Component<S & State<T>>
    {
        foo(a: T) {
            this.setState({ a: a });
                          ~~~~~~~~
!!! error TS2345: Argument of type '{ a: T; }' is not assignable to parameter of type 'Pick<S & State<T>, "a">'.
!!! error TS2345:   Types of property 'a' are incompatible.
!!! error TS2345:     Type 'T' is not assignable to type 'S["a"] & T'.
!!! error TS2345:       Type 'Foo' is not assignable to type 'S["a"] & T'.
!!! error TS2345:         Type 'Foo' is not assignable to type 'S["a"]'.
!!! error TS2345:           'S["a"]' could be instantiated with an arbitrary type which could be unrelated to 'Foo'.
        }
    }