File: deepComparisons.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 (68 lines) | stat: -rw-r--r-- 3,726 bytes parent folder | download | duplicates (3)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
tests/cases/compiler/deepComparisons.ts(2,9): error TS2322: Type 'T' is not assignable to type 'Extract<T, string>'.
tests/cases/compiler/deepComparisons.ts(3,9): error TS2322: Type 'T[K1]' is not assignable to type 'Extract<T[K1], string>'.
  Type 'T[keyof T]' is not assignable to type 'Extract<T[K1], string>'.
    Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'Extract<T[K1], string>'.
      Type 'T[string]' is not assignable to type 'Extract<T[K1], string>'.
tests/cases/compiler/deepComparisons.ts(4,9): error TS2322: Type 'T[K1][K2]' is not assignable to type 'Extract<T[K1][K2], string>'.
  Type 'T[K1][keyof T[K1]]' is not assignable to type 'Extract<T[K1][K2], string>'.
    Type 'T[K1][string] | T[K1][number] | T[K1][symbol]' is not assignable to type 'Extract<T[K1][K2], string>'.
      Type 'T[K1][string]' is not assignable to type 'Extract<T[K1][K2], string>'.
        Type 'T[keyof T][string]' is not assignable to type 'Extract<T[K1][K2], string>'.
          Type 'T[string][string] | T[number][string] | T[symbol][string]' is not assignable to type 'Extract<T[K1][K2], string>'.
            Type 'T[string][string]' is not assignable to type 'Extract<T[K1][K2], string>'.


==== tests/cases/compiler/deepComparisons.ts (3 errors) ====
    function f1<T, K1 extends keyof T, K2 extends keyof T[K1]>() {
        let v1: Extract<T, string> = 0 as any as T;  // Error
            ~~
!!! error TS2322: Type 'T' is not assignable to type 'Extract<T, string>'.
        let v2: Extract<T[K1], string> = 0 as any as T[K1];  // Error
            ~~
!!! error TS2322: Type 'T[K1]' is not assignable to type 'Extract<T[K1], string>'.
!!! error TS2322:   Type 'T[keyof T]' is not assignable to type 'Extract<T[K1], string>'.
!!! error TS2322:     Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'Extract<T[K1], string>'.
!!! error TS2322:       Type 'T[string]' is not assignable to type 'Extract<T[K1], string>'.
        let v3: Extract<T[K1][K2], string> = 0 as any as T[K1][K2];  // No error
            ~~
!!! error TS2322: Type 'T[K1][K2]' is not assignable to type 'Extract<T[K1][K2], string>'.
!!! error TS2322:   Type 'T[K1][keyof T[K1]]' is not assignable to type 'Extract<T[K1][K2], string>'.
!!! error TS2322:     Type 'T[K1][string] | T[K1][number] | T[K1][symbol]' is not assignable to type 'Extract<T[K1][K2], string>'.
!!! error TS2322:       Type 'T[K1][string]' is not assignable to type 'Extract<T[K1][K2], string>'.
!!! error TS2322:         Type 'T[keyof T][string]' is not assignable to type 'Extract<T[K1][K2], string>'.
!!! error TS2322:           Type 'T[string][string] | T[number][string] | T[symbol][string]' is not assignable to type 'Extract<T[K1][K2], string>'.
!!! error TS2322:             Type 'T[string][string]' is not assignable to type 'Extract<T[K1][K2], string>'.
    }
    
    type Foo<T> = { x: Foo<T> };
    type Bar<T> = { x: Bar<T[]> };
    
    function f2<U>() {
        let x: Foo<U> = 0 as any as Bar<U>;  // Error, excessive stack depth
    }
    
    type Foo1<T> = { x: Foo2<T> };
    type Foo2<T> = { x: Foo1<T> };
    
    function f3<U>() {
        let x: Foo1<U> = 0 as any as Bar<U>;  // No error!
    }
    
    // Repro from #46500
    
    type F<T> = {} & (
        T extends [any, ...any[]]
            ? { [K in keyof T]?: F<T[K]> }
            : T extends any[]
                ? F<T[number]>[]
                : T extends { [K: string]: any }
                    ? { [K in keyof T]?: F<T[K]> }
                    : { x: string }
    );
    
    declare function f<T = any>(): F<T>;
    
    function g() {
        return f() as F<any>;
    }