44c63a757e
* Always cache relations involving intersection types * Accept new baselines * Add regression test
85 lines
5.7 KiB
Plaintext
85 lines
5.7 KiB
Plaintext
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';
|
|
|