File: complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.errors.txt

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (85 lines) | stat: -rw-r--r-- 5,847 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
tests/cases/compiler/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.ts(33,5): error TS2322: Type '{ type: T; localChannelId: string; }' is not assignable to type 'NewChannel<ChannelOfType<T, TextChannel> | ChannelOfType<T, EmailChannel>>'.
  Type '{ type: T; localChannelId: string; }' is not assignable to type 'Pick<ChannelOfType<T, TextChannel> | ChannelOfType<T, EmailChannel>, "type">'.
    Types of property 'type' are incompatible.
      Type 'T' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
        Type '"text" | "email"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
          Type '"text"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
            Type '"text"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
              Type 'T' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
                Type '"text" | "email"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
                  Type '"text"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
                    Type '"text"' is not assignable to type 'T & "text"'.
                      Type 'T' is not assignable to type 'T & "text"'.
                        Type '"text" | "email"' is not assignable to type 'T & "text"'.
                          Type '"text"' is not assignable to type 'T & "text"'.
                            Type '"text"' is not assignable to type 'T'.
                              '"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'.
                                Type 'T' is not assignable to type '"text"'.
                                  Type '"text" | "email"' is not assignable to type '"text"'.
                                    Type '"email"' is not assignable to type '"text"'.


==== tests/cases/compiler/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.ts (1 errors) ====
    interface TextChannel {
        id: string;
        type: 'text';
        phoneNumber: string;
    }
    
    interface EmailChannel {
        id: string;
        type: 'email';
        addres: string;
    }
    
    type Channel = TextChannel | EmailChannel;
    
    export type ChannelType = Channel extends { type: infer R } ? R : never;
    
    type Omit<T, K extends keyof T> = Pick<
        T,
        ({ [P in keyof T]: P } & { [P in K]: never } & { [x: string]: never })[keyof T]
    >;
    
    type ChannelOfType<T extends ChannelType, A = Channel> = A extends { type: T }
        ? A
        : never;
    
    
    export type NewChannel<T extends Channel> = Pick<T, 'type'> &
        Partial<Omit<T, 'type' | 'id'>> & { localChannelId: string };
    
    
    export function makeNewChannel<T extends ChannelType>(type: T): NewChannel<ChannelOfType<T>> {
        const localChannelId = `blahblahblah`;
        return { type, localChannelId };
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ type: T; localChannelId: string; }' is not assignable to type 'NewChannel<ChannelOfType<T, TextChannel> | ChannelOfType<T, EmailChannel>>'.
!!! error TS2322:   Type '{ type: T; localChannelId: string; }' is not assignable to type 'Pick<ChannelOfType<T, TextChannel> | ChannelOfType<T, EmailChannel>, "type">'.
!!! error TS2322:     Types of property 'type' are incompatible.
!!! error TS2322:       Type 'T' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
!!! error TS2322:         Type '"text" | "email"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
!!! error TS2322:           Type '"text"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"] & ChannelOfType<T, EmailChannel>["type"]'.
!!! error TS2322:             Type '"text"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
!!! error TS2322:               Type 'T' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
!!! error TS2322:                 Type '"text" | "email"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
!!! error TS2322:                   Type '"text"' is not assignable to type 'ChannelOfType<T, TextChannel>["type"]'.
!!! error TS2322:                     Type '"text"' is not assignable to type 'T & "text"'.
!!! error TS2322:                       Type 'T' is not assignable to type 'T & "text"'.
!!! error TS2322:                         Type '"text" | "email"' is not assignable to type 'T & "text"'.
!!! error TS2322:                           Type '"text"' is not assignable to type 'T & "text"'.
!!! error TS2322:                             Type '"text"' is not assignable to type 'T'.
!!! error TS2322:                               '"text"' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '"text" | "email"'.
!!! error TS2322:                                 Type 'T' is not assignable to type '"text"'.
!!! error TS2322:                                   Type '"text" | "email"' is not assignable to type '"text"'.
!!! error TS2322:                                     Type '"email"' is not assignable to type '"text"'.
    }
    
    const newTextChannel = makeNewChannel('text');
    // This should work
    newTextChannel.phoneNumber = '613-555-1234';
    
    const newTextChannel2 : NewChannel<TextChannel> = makeNewChannel('text');
    // Compare with this, which ofc works.
    newTextChannel2.phoneNumber = '613-555-1234';