Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break Pick and Omit #53188

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@ type Readonly<T> = {
* From T, pick a set of properties whose keys are in the union K
*/
type Pick<T, K extends keyof T> = {
[P in K]: T[P];
[P in keyof T as K & P]: T[P];
};

/**
Expand All @@ -1582,7 +1582,7 @@ type Extract<T, U> = T extends U ? T : never;
/**
* Construct a type with the properties of T except for those in type K.
*/
type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
type Omit<T, K extends keyof any> = { [P in keyof T as Exclude<P, K>]: T[P]; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably also be multi‑line:

Suggested change
type Omit<T, K extends keyof any> = { [P in keyof T as Exclude<P, K>]: T[P]; }
type Omit<T, K extends keyof any> = {
[P in keyof T as Exclude<P, K>]: T[P];
};


/**
* Exclude null and undefined from T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export type Matching<InjectedProps, DecorationTargetProps> = {
};

export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
>Omit : Omit<T, K>
>Omit : Pick<T, Exclude<keyof T, K>>

export type InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> =
>InferableComponentEnhancerWithProps : InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=== tests/cases/compiler/circularlySimplifyingConditionalTypesNoCrash.ts ===
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
>Omit : Omit<T, K>
>Omit : Pick<T, Exclude<keyof T, K>>

type Shared< // Circularly self constraining type, defered thanks to mapping
>Shared : Shared<InjectedProps, DecorationTargetProps>
Expand Down Expand Up @@ -54,7 +54,7 @@ declare var connect: Connect;

const myStoreConnect: Connect = function(
>myStoreConnect : Connect
>function( mapStateToProps?: any, mapDispatchToProps?: any, mergeProps?: any, options: unknown = {},) { return connect( mapStateToProps, mapDispatchToProps, mergeProps, options, );} : <TStateProps, TOwnProps>(mapStateToProps?: any, mapDispatchToProps?: any, mergeProps?: any, options?: unknown) => InferableComponentEnhancerWithProps<TStateProps, Omit<P, Extract<keyof TStateProps, keyof P>> & TOwnProps>
>function( mapStateToProps?: any, mapDispatchToProps?: any, mergeProps?: any, options: unknown = {},) { return connect( mapStateToProps, mapDispatchToProps, mergeProps, options, );} : <TStateProps, TOwnProps>(mapStateToProps?: any, mapDispatchToProps?: any, mergeProps?: any, options?: unknown) => InferableComponentEnhancerWithProps<unknown, Pick<P, Exclude<keyof P, Extract<keyof TStateProps, keyof P>>> & TOwnProps>

mapStateToProps?: any,
>mapStateToProps : any
Expand All @@ -71,7 +71,7 @@ const myStoreConnect: Connect = function(

) {
return connect(
>connect( mapStateToProps, mapDispatchToProps, mergeProps, options, ) : InferableComponentEnhancerWithProps<TStateProps, Omit<P, Extract<keyof TStateProps, keyof P>> & TOwnProps>
>connect( mapStateToProps, mapDispatchToProps, mergeProps, options, ) : InferableComponentEnhancerWithProps<unknown, Pick<P, Exclude<keyof P, Extract<keyof TStateProps, keyof P>>> & TOwnProps>
>connect : Connect

mapStateToProps,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
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"'.
Type '{ type: T; localChannelId: string; }' is not assignable to type 'Pick<ChannelOfType<T, EmailChannel>, "type"> & Partial<Pick<ChannelOfType<T, EmailChannel>, (({ [P in keyof ChannelOfType<T, TextChannel>]: P; } | { [P in keyof ChannelOfType<T, EmailChannel>]: P; }) & { type: never; id: never; } & { [x: string]: never; })[keyof ChannelOfType<T, TextChannel> & keyof ChannelOfType<T, EmailChannel>]>> & { localChannelId: string; }'.
Type '{ type: T; localChannelId: string; }' is not assignable to type 'Pick<ChannelOfType<T, EmailChannel>, "type">'.


==== tests/cases/compiler/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.ts (1 errors) ====
Expand Down Expand Up @@ -55,24 +39,8 @@ tests/cases/compiler/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.t
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"'.
!!! error TS2322: Type '{ type: T; localChannelId: string; }' is not assignable to type 'Pick<ChannelOfType<T, EmailChannel>, "type"> & Partial<Pick<ChannelOfType<T, EmailChannel>, (({ [P in keyof ChannelOfType<T, TextChannel>]: P; } | { [P in keyof ChannelOfType<T, EmailChannel>]: P; }) & { type: never; id: never; } & { [x: string]: never; })[keyof ChannelOfType<T, TextChannel> & keyof ChannelOfType<T, EmailChannel>]>> & { localChannelId: string; }'.
!!! error TS2322: Type '{ type: T; localChannelId: string; }' is not assignable to type 'Pick<ChannelOfType<T, EmailChannel>, "type">'.
}

const newTextChannel = makeNewChannel('text');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ const newTextChannel = makeNewChannel('text');

// This should work
newTextChannel.phoneNumber = '613-555-1234';
>newTextChannel.phoneNumber : Symbol(phoneNumber, Decl(complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.ts, 2, 17))
>newTextChannel.phoneNumber : Symbol(phoneNumber)
>newTextChannel : Symbol(newTextChannel, Decl(complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.ts, 35, 5))
>phoneNumber : Symbol(phoneNumber, Decl(complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.ts, 2, 17))
>phoneNumber : Symbol(phoneNumber)

const newTextChannel2 : NewChannel<TextChannel> = makeNewChannel('text');
>newTextChannel2 : Symbol(newTextChannel2, Decl(complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.ts, 39, 5))
Expand All @@ -124,7 +124,7 @@ const newTextChannel2 : NewChannel<TextChannel> = makeNewChannel('text');

// Compare with this, which ofc works.
newTextChannel2.phoneNumber = '613-555-1234';
>newTextChannel2.phoneNumber : Symbol(phoneNumber, Decl(complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.ts, 2, 17))
>newTextChannel2.phoneNumber : Symbol(phoneNumber)
>newTextChannel2 : Symbol(newTextChannel2, Decl(complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.ts, 39, 5))
>phoneNumber : Symbol(phoneNumber, Decl(complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.ts, 2, 17))
>phoneNumber : Symbol(phoneNumber)

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type ChannelType = Channel extends { type: infer R } ? R : never;
>type : R

type Omit<T, K extends keyof T> = Pick<
>Omit : Omit<T, K>
>Omit : Pick<T, ({ [P in keyof T]: P; } & { [P in K]: never; } & { [x: string]: never; })[keyof T]>

T,
({ [P in keyof T]: P } & { [P in K]: never } & { [x: string]: never })[keyof T]
Expand Down
48 changes: 12 additions & 36 deletions tests/baselines/reference/conditionalTypes1.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,12 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(29,5): error TS23
Type 'T["x"]' is not assignable to type '{}'.
Type 'string | undefined' is not assignable to type '{}'.
Type 'undefined' is not assignable to type '{}'.
tests/cases/conformance/types/conditional/conditionalTypes1.ts(103,5): error TS2322: Type 'FunctionProperties<T>' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'FunctionProperties<T>'.
tests/cases/conformance/types/conditional/conditionalTypes1.ts(104,5): error TS2322: Type 'NonFunctionProperties<T>' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'NonFunctionProperties<T>'.
tests/cases/conformance/types/conditional/conditionalTypes1.ts(106,5): error TS2322: Type 'NonFunctionProperties<T>' is not assignable to type 'FunctionProperties<T>'.
Type 'FunctionPropertyNames<T>' is not assignable to type 'NonFunctionPropertyNames<T>'.
Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
Type 'string | number | symbol' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
Type 'string' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
Type 'keyof T' is not assignable to type 'never'.
Type 'string | number | symbol' is not assignable to type 'never'.
Type 'string' is not assignable to type 'never'.
tests/cases/conformance/types/conditional/conditionalTypes1.ts(108,5): error TS2322: Type 'FunctionProperties<T>' is not assignable to type 'NonFunctionProperties<T>'.
Type 'NonFunctionPropertyNames<T>' is not assignable to type 'FunctionPropertyNames<T>'.
Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
Type 'string | number | symbol' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
Type 'string' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
Type 'keyof T' is not assignable to type 'never'.
tests/cases/conformance/types/conditional/conditionalTypes1.ts(103,5): error TS2322: Type 'Pick<T, FunctionPropertyNames<T>>' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'Pick<T, FunctionPropertyNames<T>>'.
tests/cases/conformance/types/conditional/conditionalTypes1.ts(104,5): error TS2322: Type 'Pick<T, NonFunctionPropertyNames<T>>' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'Pick<T, NonFunctionPropertyNames<T>>'.
tests/cases/conformance/types/conditional/conditionalTypes1.ts(106,5): error TS2322: Type 'Pick<T, NonFunctionPropertyNames<T>>' is not assignable to type 'Pick<T, FunctionPropertyNames<T>>'.
tests/cases/conformance/types/conditional/conditionalTypes1.ts(108,5): error TS2322: Type 'Pick<T, FunctionPropertyNames<T>>' is not assignable to type 'Pick<T, NonFunctionPropertyNames<T>>'.
tests/cases/conformance/types/conditional/conditionalTypes1.ts(114,5): error TS2322: Type 'keyof T' is not assignable to type 'FunctionPropertyNames<T>'.
Type 'string | number | symbol' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
Type 'string' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
Expand Down Expand Up @@ -200,32 +188,20 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS
function f7<T>(x: T, y: FunctionProperties<T>, z: NonFunctionProperties<T>) {
x = y; // Error
~
!!! error TS2322: Type 'FunctionProperties<T>' is not assignable to type 'T'.
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'FunctionProperties<T>'.
!!! error TS2322: Type 'Pick<T, FunctionPropertyNames<T>>' is not assignable to type 'T'.
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Pick<T, FunctionPropertyNames<T>>'.
x = z; // Error
~
!!! error TS2322: Type 'NonFunctionProperties<T>' is not assignable to type 'T'.
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'NonFunctionProperties<T>'.
!!! error TS2322: Type 'Pick<T, NonFunctionPropertyNames<T>>' is not assignable to type 'T'.
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Pick<T, NonFunctionPropertyNames<T>>'.
y = x;
y = z; // Error
~
!!! error TS2322: Type 'NonFunctionProperties<T>' is not assignable to type 'FunctionProperties<T>'.
!!! error TS2322: Type 'FunctionPropertyNames<T>' is not assignable to type 'NonFunctionPropertyNames<T>'.
!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
!!! error TS2322: Type 'string' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
!!! error TS2322: Type 'keyof T' is not assignable to type 'never'.
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'never'.
!!! error TS2322: Type 'string' is not assignable to type 'never'.
!!! error TS2322: Type 'Pick<T, NonFunctionPropertyNames<T>>' is not assignable to type 'Pick<T, FunctionPropertyNames<T>>'.
z = x;
z = y; // Error
~
!!! error TS2322: Type 'FunctionProperties<T>' is not assignable to type 'NonFunctionProperties<T>'.
!!! error TS2322: Type 'NonFunctionPropertyNames<T>' is not assignable to type 'FunctionPropertyNames<T>'.
!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
!!! error TS2322: Type 'string' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'.
!!! error TS2322: Type 'keyof T' is not assignable to type 'never'.
!!! error TS2322: Type 'Pick<T, FunctionPropertyNames<T>>' is not assignable to type 'Pick<T, NonFunctionPropertyNames<T>>'.
}

function f8<T>(x: keyof T, y: FunctionPropertyNames<T>, z: NonFunctionPropertyNames<T>) {
Expand Down
36 changes: 18 additions & 18 deletions tests/baselines/reference/conditionalTypes1.types
Original file line number Diff line number Diff line change
Expand Up @@ -229,55 +229,55 @@ type FunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? K : ne
>FunctionPropertyNames : FunctionPropertyNames<T>

type FunctionProperties<T> = Pick<T, FunctionPropertyNames<T>>;
>FunctionProperties : FunctionProperties<T>
>FunctionProperties : Pick<T, FunctionPropertyNames<T>>

type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];
>NonFunctionPropertyNames : NonFunctionPropertyNames<T>

type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;
>NonFunctionProperties : NonFunctionProperties<T>
>NonFunctionProperties : Pick<T, NonFunctionPropertyNames<T>>

type T30 = FunctionProperties<Part>;
>T30 : { updatePart: (newName: string) => void; }
>T30 : Pick<Part, "updatePart">

type T31 = NonFunctionProperties<Part>;
>T31 : { id: number; name: string; subparts: Part[]; }
>T31 : Pick<Part, NonFunctionPropertyNames<Part>>

function f7<T>(x: T, y: FunctionProperties<T>, z: NonFunctionProperties<T>) {
>f7 : <T>(x: T, y: FunctionProperties<T>, z: NonFunctionProperties<T>) => void
>x : T
>y : FunctionProperties<T>
>z : NonFunctionProperties<T>
>y : Pick<T, FunctionPropertyNames<T>>
>z : Pick<T, NonFunctionPropertyNames<T>>

x = y; // Error
>x = y : FunctionProperties<T>
>x = y : Pick<T, FunctionPropertyNames<T>>
>x : T
>y : FunctionProperties<T>
>y : Pick<T, FunctionPropertyNames<T>>

x = z; // Error
>x = z : NonFunctionProperties<T>
>x = z : Pick<T, NonFunctionPropertyNames<T>>
>x : T
>z : NonFunctionProperties<T>
>z : Pick<T, NonFunctionPropertyNames<T>>

y = x;
>y = x : T
>y : FunctionProperties<T>
>y : Pick<T, FunctionPropertyNames<T>>
>x : T

y = z; // Error
>y = z : NonFunctionProperties<T>
>y : FunctionProperties<T>
>z : NonFunctionProperties<T>
>y = z : Pick<T, NonFunctionPropertyNames<T>>
>y : Pick<T, FunctionPropertyNames<T>>
>z : Pick<T, NonFunctionPropertyNames<T>>

z = x;
>z = x : T
>z : NonFunctionProperties<T>
>z : Pick<T, NonFunctionPropertyNames<T>>
>x : T

z = y; // Error
>z = y : FunctionProperties<T>
>z : NonFunctionProperties<T>
>y : FunctionProperties<T>
>z = y : Pick<T, FunctionPropertyNames<T>>
>z : Pick<T, NonFunctionPropertyNames<T>>
>y : Pick<T, FunctionPropertyNames<T>>
}

function f8<T>(x: keyof T, y: FunctionPropertyNames<T>, z: NonFunctionPropertyNames<T>) {
Expand Down
Loading