diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index a74b3cb4c2111..34fcbcd3810d3 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -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]; }; /** @@ -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]; } /** * Exclude null and undefined from T diff --git a/tests/baselines/reference/circularlyConstrainedMappedTypeContainingConditionalNoInfiniteInstantiationDepth.types b/tests/baselines/reference/circularlyConstrainedMappedTypeContainingConditionalNoInfiniteInstantiationDepth.types index 86ebc30dfb1b2..fd1938da0a8ae 100644 --- a/tests/baselines/reference/circularlyConstrainedMappedTypeContainingConditionalNoInfiniteInstantiationDepth.types +++ b/tests/baselines/reference/circularlyConstrainedMappedTypeContainingConditionalNoInfiniteInstantiationDepth.types @@ -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> diff --git a/tests/baselines/reference/circularlySimplifyingConditionalTypesNoCrash.types b/tests/baselines/reference/circularlySimplifyingConditionalTypesNoCrash.types index 7178020defb57..b1dae02206084 100644 --- a/tests/baselines/reference/circularlySimplifyingConditionalTypesNoCrash.types +++ b/tests/baselines/reference/circularlySimplifyingConditionalTypesNoCrash.types @@ -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> @@ -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 @@ -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, diff --git a/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.errors.txt b/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.errors.txt index 19d2dd696e097..0b3515a9e54ac 100644 --- a/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.errors.txt +++ b/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.errors.txt @@ -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) ==== @@ -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'); diff --git a/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.symbols b/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.symbols index 5e1a8671422ec..165f305600772 100644 --- a/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.symbols +++ b/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.symbols @@ -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)) @@ -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) diff --git a/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.types b/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.types index a499495da42c2..fdb1c322ebfde 100644 --- a/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.types +++ b/tests/baselines/reference/complicatedIndexedAccessKeyofReliesOnKeyofNeverUpperBound.types @@ -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] diff --git a/tests/baselines/reference/conditionalTypes1.errors.txt b/tests/baselines/reference/conditionalTypes1.errors.txt index eac67704de79a..26429be9a3167 100644 --- a/tests/baselines/reference/conditionalTypes1.errors.txt +++ b/tests/baselines/reference/conditionalTypes1.errors.txt @@ -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'. @@ -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>) { diff --git a/tests/baselines/reference/conditionalTypes1.types b/tests/baselines/reference/conditionalTypes1.types index d4d756f7396cc..bce62b9c4d188 100644 --- a/tests/baselines/reference/conditionalTypes1.types +++ b/tests/baselines/reference/conditionalTypes1.types @@ -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>) { diff --git a/tests/baselines/reference/conditionalTypes2.types b/tests/baselines/reference/conditionalTypes2.types index 8c72188b7925e..2ebb32b05399b 100644 --- a/tests/baselines/reference/conditionalTypes2.types +++ b/tests/baselines/reference/conditionalTypes2.types @@ -489,7 +489,7 @@ declare type IResponse<T> = { sendValue(name: keyof GetAllPropertiesOfType<T, string>): void; >sendValue : (name: keyof GetAllPropertiesOfType<T, string>) => void ->name : GetPropertyNamesOfType<Required<T>, string> +>name : keyof Pick<T, GetPropertyNamesOfType<Required<T>, string>> }; @@ -500,7 +500,7 @@ declare type GetPropertyNamesOfType<T, RestrictToType> = { }[Extract<keyof T, string>]; declare type GetAllPropertiesOfType<T, RestrictToType> = Pick< ->GetAllPropertiesOfType : GetAllPropertiesOfType<T, RestrictToType> +>GetAllPropertiesOfType : Pick<T, GetPropertyNamesOfType<Required<T>, RestrictToType>> T, GetPropertyNamesOfType<Required<T>, RestrictToType> diff --git a/tests/baselines/reference/conditionalTypesSimplifyWhenTrivial.errors.txt b/tests/baselines/reference/conditionalTypesSimplifyWhenTrivial.errors.txt new file mode 100644 index 0000000000000..129b4e8e70b9e --- /dev/null +++ b/tests/baselines/reference/conditionalTypesSimplifyWhenTrivial.errors.txt @@ -0,0 +1,98 @@ +tests/cases/compiler/conditionalTypesSimplifyWhenTrivial.ts(3,14): error TS2322: Type 'Pick<Params, Exclude<keyof Params, never>>' is not assignable to type 'Params'. + 'Params' could be instantiated with an arbitrary type which could be unrelated to 'Pick<Params, Exclude<keyof Params, never>>'. +tests/cases/compiler/conditionalTypesSimplifyWhenTrivial.ts(12,14): error TS2322: Type 'Pick<Params, Extract<keyof Params, keyof Params>>' is not assignable to type 'Params'. + 'Params' could be instantiated with an arbitrary type which could be unrelated to 'Pick<Params, Extract<keyof Params, keyof Params>>'. +tests/cases/compiler/conditionalTypesSimplifyWhenTrivial.ts(27,14): error TS2322: Type 'Pick<Params, ExcludeWithDefault<keyof Params, never, never>>' is not assignable to type 'Params'. + 'Params' could be instantiated with an arbitrary type which could be unrelated to 'Pick<Params, ExcludeWithDefault<keyof Params, never, never>>'. +tests/cases/compiler/conditionalTypesSimplifyWhenTrivial.ts(36,14): error TS2322: Type 'Pick<Params, ExtractWithDefault<keyof Params, keyof Params, never>>' is not assignable to type 'Params'. + 'Params' could be instantiated with an arbitrary type which could be unrelated to 'Pick<Params, ExtractWithDefault<keyof Params, keyof Params, never>>'. +tests/cases/compiler/conditionalTypesSimplifyWhenTrivial.ts(47,14): error TS2322: Type 'Pick<Params, TemplatedConditional<keyof Params, never, never, keyof Params>>' is not assignable to type 'Params'. + 'Params' could be instantiated with an arbitrary type which could be unrelated to 'Pick<Params, TemplatedConditional<keyof Params, never, never, keyof Params>>'. +tests/cases/compiler/conditionalTypesSimplifyWhenTrivial.ts(56,14): error TS2322: Type 'Pick<Params, TemplatedConditional<keyof Params, keyof Params, keyof Params, never>>' is not assignable to type 'Params'. + 'Params' could be instantiated with an arbitrary type which could be unrelated to 'Pick<Params, TemplatedConditional<keyof Params, keyof Params, keyof Params, never>>'. + + +==== tests/cases/compiler/conditionalTypesSimplifyWhenTrivial.ts (6 errors) ==== + const fn1 = <Params>( + params: Pick<Params, Exclude<keyof Params, never>>, + ): Params => params; + ~~~~~~ +!!! error TS2322: Type 'Pick<Params, Exclude<keyof Params, never>>' is not assignable to type 'Params'. +!!! error TS2322: 'Params' could be instantiated with an arbitrary type which could be unrelated to 'Pick<Params, Exclude<keyof Params, never>>'. + + function fn2<T>(x: Exclude<T, never>) { + var y: T = x; + x = y; + } + + const fn3 = <Params>( + params: Pick<Params, Extract<keyof Params, keyof Params>>, + ): Params => params; + ~~~~~~ +!!! error TS2322: Type 'Pick<Params, Extract<keyof Params, keyof Params>>' is not assignable to type 'Params'. +!!! error TS2322: 'Params' could be instantiated with an arbitrary type which could be unrelated to 'Pick<Params, Extract<keyof Params, keyof Params>>'. + + function fn4<T>(x: Extract<T, T>) { + var y: T = x; + x = y; + } + + declare var x: Extract<number | string, any>; // Should be `numebr | string` and not `any` + + type ExtractWithDefault<T, U, D = never> = T extends U ? T : D; + + type ExcludeWithDefault<T, U, D = never> = T extends U ? D : T; + + const fn5 = <Params>( + params: Pick<Params, ExcludeWithDefault<keyof Params, never>>, + ): Params => params; + ~~~~~~ +!!! error TS2322: Type 'Pick<Params, ExcludeWithDefault<keyof Params, never, never>>' is not assignable to type 'Params'. +!!! error TS2322: 'Params' could be instantiated with an arbitrary type which could be unrelated to 'Pick<Params, ExcludeWithDefault<keyof Params, never, never>>'. + + function fn6<T>(x: ExcludeWithDefault<T, never>) { + var y: T = x; + x = y; + } + + const fn7 = <Params>( + params: Pick<Params, ExtractWithDefault<keyof Params, keyof Params>>, + ): Params => params; + ~~~~~~ +!!! error TS2322: Type 'Pick<Params, ExtractWithDefault<keyof Params, keyof Params, never>>' is not assignable to type 'Params'. +!!! error TS2322: 'Params' could be instantiated with an arbitrary type which could be unrelated to 'Pick<Params, ExtractWithDefault<keyof Params, keyof Params, never>>'. + + function fn8<T>(x: ExtractWithDefault<T, T>) { + var y: T = x; + x = y; + } + + type TemplatedConditional<TCheck, TExtends, TTrue, TFalse> = TCheck extends TExtends ? TTrue : TFalse; + + const fn9 = <Params>( + params: Pick<Params, TemplatedConditional<keyof Params, never, never, keyof Params>>, + ): Params => params; + ~~~~~~ +!!! error TS2322: Type 'Pick<Params, TemplatedConditional<keyof Params, never, never, keyof Params>>' is not assignable to type 'Params'. +!!! error TS2322: 'Params' could be instantiated with an arbitrary type which could be unrelated to 'Pick<Params, TemplatedConditional<keyof Params, never, never, keyof Params>>'. + + function fn10<T>(x: TemplatedConditional<T, never, never, T>) { + var y: T = x; + x = y; + } + + const fn11 = <Params>( + params: Pick<Params, TemplatedConditional<keyof Params, keyof Params, keyof Params, never>>, + ): Params => params; + ~~~~~~ +!!! error TS2322: Type 'Pick<Params, TemplatedConditional<keyof Params, keyof Params, keyof Params, never>>' is not assignable to type 'Params'. +!!! error TS2322: 'Params' could be instantiated with an arbitrary type which could be unrelated to 'Pick<Params, TemplatedConditional<keyof Params, keyof Params, keyof Params, never>>'. + + function fn12<T>(x: TemplatedConditional<T, T, T, never>) { + var y: T = x; + x = y; + } + + declare var z: any; + const zee = z!!!; // since x is `any`, `x extends null | undefined` should be both true and false - and thus yield `any` + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols b/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols index 557afeeffa912..5a05c37175e96 100644 --- a/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols +++ b/tests/baselines/reference/destructuringUnspreadableIntoRest.symbols @@ -50,9 +50,9 @@ class A { >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) rest1.publicProp; ->rest1.publicProp : Symbol(publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>rest1.publicProp : Symbol(publicProp) >rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 14, 15)) ->publicProp : Symbol(publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>publicProp : Symbol(publicProp) rest2.publicProp; >rest2.publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) @@ -157,9 +157,9 @@ function destructure<T extends A>(x: T) { >A : Symbol(A, Decl(destructuringUnspreadableIntoRest.ts, 0, 0)) rest1.publicProp; ->rest1.publicProp : Symbol(publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>rest1.publicProp : Symbol(publicProp) >rest1 : Symbol(rest1, Decl(destructuringUnspreadableIntoRest.ts, 52, 11)) ->publicProp : Symbol(publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) +>publicProp : Symbol(publicProp) rest2.publicProp; >rest2.publicProp : Symbol(A.publicProp, Decl(destructuringUnspreadableIntoRest.ts, 1, 16)) diff --git a/tests/baselines/reference/genericIndexedAccessVarianceComparisonResultCorrect.types b/tests/baselines/reference/genericIndexedAccessVarianceComparisonResultCorrect.types index e04f48ba89210..61fe1d60f49eb 100644 --- a/tests/baselines/reference/genericIndexedAccessVarianceComparisonResultCorrect.types +++ b/tests/baselines/reference/genericIndexedAccessVarianceComparisonResultCorrect.types @@ -24,14 +24,14 @@ class B { } type T<X extends { x: any }> = Pick<X, 'x'>; ->T : T<X> +>T : Pick<X, "x"> >x : any type C = T<A>; ->C : { x: string; } +>C : Pick<A, "x"> type D = T<B>; ->D : { x: string; } +>D : Pick<B, "x"> type C_extends_D = C extends D ? true : false; // true >C_extends_D : true @@ -49,24 +49,24 @@ type TA_extends_TB = T<A> extends T<B> ? true : false; >false : false declare let a: T<A>; ->a : T<A> +>a : Pick<A, "x"> declare let b: T<B>; ->b : T<B> +>b : Pick<B, "x"> declare let c: C; ->c : C +>c : Pick<A, "x"> declare let d: D; ->d : D +>d : Pick<B, "x"> b = a; // should be no error ->b = a : T<A> ->b : T<B> ->a : T<A> +>b = a : Pick<A, "x"> +>b : Pick<B, "x"> +>a : Pick<A, "x"> c = d; ->c = d : D ->c : C ->d : D +>c = d : Pick<B, "x"> +>c : Pick<A, "x"> +>d : Pick<B, "x"> diff --git a/tests/baselines/reference/genericObjectSpreadResultInSwitch.symbols b/tests/baselines/reference/genericObjectSpreadResultInSwitch.symbols index 56868aee4e94f..aa6f806f7582d 100644 --- a/tests/baselines/reference/genericObjectSpreadResultInSwitch.symbols +++ b/tests/baselines/reference/genericObjectSpreadResultInSwitch.symbols @@ -48,10 +48,10 @@ switch (params.tag) { // TS 4.3: string | number const result = getType(params).type; >result : Symbol(result, Decl(genericObjectSpreadResultInSwitch.ts, 21, 13)) ->getType(params).type : Symbol(type, Decl(genericObjectSpreadResultInSwitch.ts, 2, 16)) +>getType(params).type : Symbol(type) >getType : Symbol(getType, Decl(genericObjectSpreadResultInSwitch.ts, 4, 5)) >params : Symbol(params, Decl(genericObjectSpreadResultInSwitch.ts, 15, 13)) ->type : Symbol(type, Decl(genericObjectSpreadResultInSwitch.ts, 2, 16)) +>type : Symbol(type) break; } @@ -60,10 +60,10 @@ switch (params.tag) { // TS 4.3: string | number const result = getType(params).type; >result : Symbol(result, Decl(genericObjectSpreadResultInSwitch.ts, 28, 13)) ->getType(params).type : Symbol(type, Decl(genericObjectSpreadResultInSwitch.ts, 2, 45)) +>getType(params).type : Symbol(type) >getType : Symbol(getType, Decl(genericObjectSpreadResultInSwitch.ts, 4, 5)) >params : Symbol(params, Decl(genericObjectSpreadResultInSwitch.ts, 15, 13)) ->type : Symbol(type, Decl(genericObjectSpreadResultInSwitch.ts, 2, 45)) +>type : Symbol(type) break; } diff --git a/tests/baselines/reference/indexedAccessRelation.errors.txt b/tests/baselines/reference/indexedAccessRelation.errors.txt index 22d90aeacad27..c41f7aa2bd729 100644 --- a/tests/baselines/reference/indexedAccessRelation.errors.txt +++ b/tests/baselines/reference/indexedAccessRelation.errors.txt @@ -1,9 +1,4 @@ -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(16,23): error TS2345: Argument of type '{ a: T; }' is not assignable to parameter of type 'Pick<S & State<T>, keyof S | "a">'. ==== tests/cases/compiler/indexedAccessRelation.ts (1 errors) ==== @@ -24,12 +19,7 @@ tests/cases/compiler/indexedAccessRelation.ts(16,23): error TS2345: Argument of 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'. +!!! error TS2345: Argument of type '{ a: T; }' is not assignable to parameter of type 'Pick<S & State<T>, keyof S | "a">'. } } \ No newline at end of file diff --git a/tests/baselines/reference/indexedAccessRetainsIndexSignature.types b/tests/baselines/reference/indexedAccessRetainsIndexSignature.types index fa1dafca6dc0a..32596ad6e17b9 100644 --- a/tests/baselines/reference/indexedAccessRetainsIndexSignature.types +++ b/tests/baselines/reference/indexedAccessRetainsIndexSignature.types @@ -6,10 +6,10 @@ type Diff<T extends keyof any, U extends keyof any> = >x : string type Omit<U, K extends keyof U> = Pick<U, Diff<keyof U, K>> ->Omit : Omit<U, K> +>Omit : Pick<U, Diff<keyof U, K>> type Omit1<U, K extends keyof U> = Pick<U, Diff<keyof U, K>>; ->Omit1 : Omit1<U, K> +>Omit1 : Pick<U, Diff<keyof U, K>> // is in fact an equivalent of @@ -17,12 +17,12 @@ type Omit2<T, K extends keyof T> = {[P in Diff<keyof T, K>]: T[P]}; >Omit2 : Omit2<T, K> type O = Omit<{ a: number, b: string }, 'a'> ->O : { b: string; } +>O : Pick<{ a: number; b: string; }, "b"> >a : number >b : string export const o: O = { b: '' } ->o : O +>o : Pick<{ a: number; b: string; }, "b"> >{ b: '' } : { b: string; } >b : string >'' : "" diff --git a/tests/baselines/reference/inferConditionalConstraintMappedMember.types b/tests/baselines/reference/inferConditionalConstraintMappedMember.types index 7732a8658a18a..40285b10ea8dd 100644 --- a/tests/baselines/reference/inferConditionalConstraintMappedMember.types +++ b/tests/baselines/reference/inferConditionalConstraintMappedMember.types @@ -16,7 +16,7 @@ type test = KeysWithoutStringIndex<{ [index: string]: string; foo: string; bar: // KeysWithoutStringIndex<T> will always be a subset of keyof T, but is reported as unassignable export type RemoveIdxSgn<T> = Pick<T, KeysWithoutStringIndex<T>> ->RemoveIdxSgn : RemoveIdxSgn<T> +>RemoveIdxSgn : Pick<T, KeysWithoutStringIndex<T>> // ERROR: // Type 'KeysWithoutStringIndex<T>' does not satisfy the constraint 'keyof T'. diff --git a/tests/baselines/reference/isomorphicMappedTypeInference.js b/tests/baselines/reference/isomorphicMappedTypeInference.js index 6e1c1b6dfd615..eae29dda98dd0 100644 --- a/tests/baselines/reference/isomorphicMappedTypeInference.js +++ b/tests/baselines/reference/isomorphicMappedTypeInference.js @@ -370,26 +370,11 @@ declare function f21<T, K extends keyof T>(obj: Pick<T, K>): K; declare function f22<T, K extends keyof T>(obj: Boxified<Pick<T, K>>): T; declare function f23<T, U extends keyof T, K extends U>(obj: Pick<T, K>): T; declare function f24<T, U, K extends keyof T | keyof U>(obj: Pick<T & U, K>): T & U; -declare let x0: { - foo: number; - bar: string; -}; -declare let x1: "foo" | "bar"; -declare let x2: { - foo: number; - bar: string; -}; -declare let x3: { - foo: number; - bar: string; -}; -declare let x4: { - foo: number; - bar: string; -} & { - foo: number; - bar: string; -}; +declare let x0: unknown; +declare let x1: never; +declare let x2: unknown; +declare let x3: unknown; +declare let x4: unknown; declare function getProps<T, K extends keyof T>(obj: T, list: K[]): Pick<T, K>; declare const myAny: any; declare const o1: Pick<any, "foo" | "bar">; diff --git a/tests/baselines/reference/isomorphicMappedTypeInference.types b/tests/baselines/reference/isomorphicMappedTypeInference.types index 5d2a897899761..f99253400da2e 100644 --- a/tests/baselines/reference/isomorphicMappedTypeInference.types +++ b/tests/baselines/reference/isomorphicMappedTypeInference.types @@ -531,8 +531,8 @@ declare function f24<T, U, K extends keyof T | keyof U>(obj: Pick<T & U, K>): T >obj : Pick<T & U, K> let x0 = f20({ foo: 42, bar: "hello" }); ->x0 : { foo: number; bar: string; } ->f20({ foo: 42, bar: "hello" }) : { foo: number; bar: string; } +>x0 : unknown +>f20({ foo: 42, bar: "hello" }) : unknown >f20 : <T, K extends keyof T>(obj: Pick<T, K>) => T >{ foo: 42, bar: "hello" } : { foo: number; bar: string; } >foo : number @@ -541,8 +541,8 @@ let x0 = f20({ foo: 42, bar: "hello" }); >"hello" : "hello" let x1 = f21({ foo: 42, bar: "hello" }); ->x1 : "foo" | "bar" ->f21({ foo: 42, bar: "hello" }) : "foo" | "bar" +>x1 : never +>f21({ foo: 42, bar: "hello" }) : never >f21 : <T, K extends keyof T>(obj: Pick<T, K>) => K >{ foo: 42, bar: "hello" } : { foo: number; bar: string; } >foo : number @@ -551,8 +551,8 @@ let x1 = f21({ foo: 42, bar: "hello" }); >"hello" : "hello" let x2 = f22({ foo: { value: 42} , bar: { value: "hello" } }); ->x2 : { foo: number; bar: string; } ->f22({ foo: { value: 42} , bar: { value: "hello" } }) : { foo: number; bar: string; } +>x2 : unknown +>f22({ foo: { value: 42} , bar: { value: "hello" } }) : unknown >f22 : <T, K extends keyof T>(obj: Boxified<Pick<T, K>>) => T >{ foo: { value: 42} , bar: { value: "hello" } } : { foo: { value: number; }; bar: { value: string; }; } >foo : { value: number; } @@ -565,8 +565,8 @@ let x2 = f22({ foo: { value: 42} , bar: { value: "hello" } }); >"hello" : "hello" let x3 = f23({ foo: 42, bar: "hello" }); ->x3 : { foo: number; bar: string; } ->f23({ foo: 42, bar: "hello" }) : { foo: number; bar: string; } +>x3 : unknown +>f23({ foo: 42, bar: "hello" }) : unknown >f23 : <T, U extends keyof T, K extends U>(obj: Pick<T, K>) => T >{ foo: 42, bar: "hello" } : { foo: number; bar: string; } >foo : number @@ -575,8 +575,8 @@ let x3 = f23({ foo: 42, bar: "hello" }); >"hello" : "hello" let x4 = f24({ foo: 42, bar: "hello" }); ->x4 : { foo: number; bar: string; } & { foo: number; bar: string; } ->f24({ foo: 42, bar: "hello" }) : { foo: number; bar: string; } & { foo: number; bar: string; } +>x4 : unknown +>f24({ foo: 42, bar: "hello" }) : unknown >f24 : <T, U, K extends keyof T | keyof U>(obj: Pick<T & U, K>) => T & U >{ foo: 42, bar: "hello" } : { foo: number; bar: string; } >foo : number diff --git a/tests/baselines/reference/keyofGenericExtendingClassDoubleLayer.types b/tests/baselines/reference/keyofGenericExtendingClassDoubleLayer.types index d3108ac94a927..bf7cf6f1f88a8 100644 --- a/tests/baselines/reference/keyofGenericExtendingClassDoubleLayer.types +++ b/tests/baselines/reference/keyofGenericExtendingClassDoubleLayer.types @@ -7,11 +7,11 @@ class Model<Attributes = any> { } type ModelAttributes<T> = Omit<T, keyof Model>; ->ModelAttributes : ModelAttributes<T> +>ModelAttributes : Omit<T, "createdAt"> class AutoModel<T> extends Model<ModelAttributes<T>> {} >AutoModel : AutoModel<T> ->Model : Model<ModelAttributes<T>> +>Model : Model<Omit<T, "createdAt">> class PersonModel extends AutoModel<PersonModel> { >PersonModel : PersonModel diff --git a/tests/baselines/reference/mappedTypeConstraints.errors.txt b/tests/baselines/reference/mappedTypeConstraints.errors.txt new file mode 100644 index 0000000000000..45b79961b520f --- /dev/null +++ b/tests/baselines/reference/mappedTypeConstraints.errors.txt @@ -0,0 +1,58 @@ +tests/cases/conformance/types/mapped/mappedTypeConstraints.ts(2,9): error TS2339: Property 'b' does not exist on type 'Pick<T, Extract<keyof T, "b">>'. +tests/cases/conformance/types/mapped/mappedTypeConstraints.ts(6,9): error TS2339: Property 'b' does not exist on type 'Pick<T, Exclude<keyof T, "a">>'. +tests/cases/conformance/types/mapped/mappedTypeConstraints.ts(10,9): error TS2339: Property 'b' does not exist on type 'Pick<T | U, keyof T & keyof U>'. + Property 'b' does not exist on type 'Pick<T, keyof T & keyof U>'. +tests/cases/conformance/types/mapped/mappedTypeConstraints.ts(14,9): error TS2339: Property 'a' does not exist on type 'Pick<T & U, keyof T | keyof U>'. +tests/cases/conformance/types/mapped/mappedTypeConstraints.ts(15,9): error TS2339: Property 'b' does not exist on type 'Pick<T & U, keyof T | keyof U>'. +tests/cases/conformance/types/mapped/mappedTypeConstraints.ts(16,9): error TS2339: Property 'c' does not exist on type 'Pick<T & U, keyof T | keyof U>'. + + +==== tests/cases/conformance/types/mapped/mappedTypeConstraints.ts (6 errors) ==== + function f0<T extends { a: string, b: string }>(obj: Pick<T, Extract<keyof T, 'b'>>) { + obj.b; + ~ +!!! error TS2339: Property 'b' does not exist on type 'Pick<T, Extract<keyof T, "b">>'. + } + + function f1<T extends { a: string, b: string }>(obj: Pick<T, Exclude<keyof T, 'a'>>) { + obj.b; + ~ +!!! error TS2339: Property 'b' does not exist on type 'Pick<T, Exclude<keyof T, "a">>'. + } + + function f2<T extends { a: string, b: string }, U extends { b: string, c: string }>(obj: Pick<T | U, keyof (T | U)>) { + obj.b; + ~ +!!! error TS2339: Property 'b' does not exist on type 'Pick<T | U, keyof T & keyof U>'. +!!! error TS2339: Property 'b' does not exist on type 'Pick<T, keyof T & keyof U>'. + } + + function f3<T extends { a: string, b: string }, U extends { b: string, c: string }>(obj: Pick<T & U, keyof (T & U)>) { + obj.a; + ~ +!!! error TS2339: Property 'a' does not exist on type 'Pick<T & U, keyof T | keyof U>'. + obj.b; + ~ +!!! error TS2339: Property 'b' does not exist on type 'Pick<T & U, keyof T | keyof U>'. + obj.c; + ~ +!!! error TS2339: Property 'c' does not exist on type 'Pick<T & U, keyof T | keyof U>'. + } + + function f4<T extends { a: string, b: string }>(obj: Record<Exclude<keyof T, 'b'> | 'c', string>) { + obj.a; + obj.c; + } + + // Repro from #28821 + + type TargetProps = { + foo: string, + bar: string + }; + + const modifier = <T extends TargetProps>(targetProps: T) => { + let {bar, ...rest} = targetProps; + rest.foo; + }; + \ No newline at end of file diff --git a/tests/baselines/reference/mappedTypeConstraints.symbols b/tests/baselines/reference/mappedTypeConstraints.symbols index 3601ffc3de848..8c9eac4c4d2aa 100644 --- a/tests/baselines/reference/mappedTypeConstraints.symbols +++ b/tests/baselines/reference/mappedTypeConstraints.symbols @@ -11,9 +11,7 @@ function f0<T extends { a: string, b: string }>(obj: Pick<T, Extract<keyof T, 'b >T : Symbol(T, Decl(mappedTypeConstraints.ts, 0, 12)) obj.b; ->obj.b : Symbol(b, Decl(mappedTypeConstraints.ts, 0, 34)) >obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 0, 48)) ->b : Symbol(b, Decl(mappedTypeConstraints.ts, 0, 34)) } function f1<T extends { a: string, b: string }>(obj: Pick<T, Exclude<keyof T, 'a'>>) { @@ -28,9 +26,7 @@ function f1<T extends { a: string, b: string }>(obj: Pick<T, Exclude<keyof T, 'a >T : Symbol(T, Decl(mappedTypeConstraints.ts, 4, 12)) obj.b; ->obj.b : Symbol(b, Decl(mappedTypeConstraints.ts, 4, 34)) >obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 4, 48)) ->b : Symbol(b, Decl(mappedTypeConstraints.ts, 4, 34)) } function f2<T extends { a: string, b: string }, U extends { b: string, c: string }>(obj: Pick<T | U, keyof (T | U)>) { @@ -49,9 +45,7 @@ function f2<T extends { a: string, b: string }, U extends { b: string, c: string >U : Symbol(U, Decl(mappedTypeConstraints.ts, 8, 47)) obj.b; ->obj.b : Symbol(b, Decl(mappedTypeConstraints.ts, 8, 34), Decl(mappedTypeConstraints.ts, 8, 59)) >obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 8, 84)) ->b : Symbol(b, Decl(mappedTypeConstraints.ts, 8, 34), Decl(mappedTypeConstraints.ts, 8, 59)) } function f3<T extends { a: string, b: string }, U extends { b: string, c: string }>(obj: Pick<T & U, keyof (T & U)>) { @@ -70,19 +64,13 @@ function f3<T extends { a: string, b: string }, U extends { b: string, c: string >U : Symbol(U, Decl(mappedTypeConstraints.ts, 12, 47)) obj.a; ->obj.a : Symbol(a, Decl(mappedTypeConstraints.ts, 12, 23)) >obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 12, 84)) ->a : Symbol(a, Decl(mappedTypeConstraints.ts, 12, 23)) obj.b; ->obj.b : Symbol(b, Decl(mappedTypeConstraints.ts, 12, 34), Decl(mappedTypeConstraints.ts, 12, 59)) >obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 12, 84)) ->b : Symbol(b, Decl(mappedTypeConstraints.ts, 12, 34), Decl(mappedTypeConstraints.ts, 12, 59)) obj.c; ->obj.c : Symbol(c, Decl(mappedTypeConstraints.ts, 12, 70)) >obj : Symbol(obj, Decl(mappedTypeConstraints.ts, 12, 84)) ->c : Symbol(c, Decl(mappedTypeConstraints.ts, 12, 70)) } function f4<T extends { a: string, b: string }>(obj: Record<Exclude<keyof T, 'b'> | 'c', string>) { @@ -132,9 +120,9 @@ const modifier = <T extends TargetProps>(targetProps: T) => { >targetProps : Symbol(targetProps, Decl(mappedTypeConstraints.ts, 30, 41)) rest.foo; ->rest.foo : Symbol(foo, Decl(mappedTypeConstraints.ts, 25, 20)) +>rest.foo : Symbol(foo) >rest : Symbol(rest, Decl(mappedTypeConstraints.ts, 31, 13)) ->foo : Symbol(foo, Decl(mappedTypeConstraints.ts, 25, 20)) +>foo : Symbol(foo) }; diff --git a/tests/baselines/reference/mappedTypeConstraints.types b/tests/baselines/reference/mappedTypeConstraints.types index 86099d594d59f..38ddb60cb0a61 100644 --- a/tests/baselines/reference/mappedTypeConstraints.types +++ b/tests/baselines/reference/mappedTypeConstraints.types @@ -6,9 +6,9 @@ function f0<T extends { a: string, b: string }>(obj: Pick<T, Extract<keyof T, 'b >obj : Pick<T, Extract<keyof T, "b">> obj.b; ->obj.b : T["b"] +>obj.b : any >obj : Pick<T, Extract<keyof T, "b">> ->b : T["b"] +>b : any } function f1<T extends { a: string, b: string }>(obj: Pick<T, Exclude<keyof T, 'a'>>) { @@ -18,9 +18,9 @@ function f1<T extends { a: string, b: string }>(obj: Pick<T, Exclude<keyof T, 'a >obj : Pick<T, Exclude<keyof T, "a">> obj.b; ->obj.b : T["b"] +>obj.b : any >obj : Pick<T, Exclude<keyof T, "a">> ->b : T["b"] +>b : any } function f2<T extends { a: string, b: string }, U extends { b: string, c: string }>(obj: Pick<T | U, keyof (T | U)>) { @@ -32,9 +32,9 @@ function f2<T extends { a: string, b: string }, U extends { b: string, c: string >obj : Pick<T | U, keyof T & keyof U> obj.b; ->obj.b : (T | U)["b"] +>obj.b : any >obj : Pick<T | U, keyof T & keyof U> ->b : (T | U)["b"] +>b : any } function f3<T extends { a: string, b: string }, U extends { b: string, c: string }>(obj: Pick<T & U, keyof (T & U)>) { @@ -46,19 +46,19 @@ function f3<T extends { a: string, b: string }, U extends { b: string, c: string >obj : Pick<T & U, keyof T | keyof U> obj.a; ->obj.a : (T & U)["a"] +>obj.a : any >obj : Pick<T & U, keyof T | keyof U> ->a : (T & U)["a"] +>a : any obj.b; ->obj.b : (T & U)["b"] +>obj.b : any >obj : Pick<T & U, keyof T | keyof U> ->b : (T & U)["b"] +>b : any obj.c; ->obj.c : (T & U)["c"] +>obj.c : any >obj : Pick<T & U, keyof T | keyof U> ->c : (T & U)["c"] +>c : any } function f4<T extends { a: string, b: string }>(obj: Record<Exclude<keyof T, 'b'> | 'c', string>) { diff --git a/tests/baselines/reference/mappedTypeErrors.errors.txt b/tests/baselines/reference/mappedTypeErrors.errors.txt index 0f627165bec5d..b692262a85cfd 100644 --- a/tests/baselines/reference/mappedTypeErrors.errors.txt +++ b/tests/baselines/reference/mappedTypeErrors.errors.txt @@ -21,9 +21,17 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(77,59): error TS2345: A Object literal may only specify known properties, and 'z' does not exist in type 'Readonly<{ x: number; y: number; }>'. tests/cases/conformance/types/mapped/mappedTypeErrors.ts(83,58): error TS2345: Argument of type '{ x: number; y: number; z: number; }' is not assignable to parameter of type 'Partial<{ x: number; y: number; }>'. Object literal may only specify known properties, and 'z' does not exist in type 'Partial<{ x: number; y: number; }>'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(102,15): error TS2345: Argument of type '{ b: undefined; }' is not assignable to parameter of type 'Pick<Foo, keyof Foo>'. + Property 'a' is missing in type '{ b: undefined; }' but required in type 'Pick<Foo, keyof Foo>'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(103,15): error TS2345: Argument of type '{}' is not assignable to parameter of type 'Pick<Foo, keyof Foo>'. + Property 'a' is missing in type '{}' but required in type 'Pick<Foo, keyof Foo>'. tests/cases/conformance/types/mapped/mappedTypeErrors.ts(105,17): error TS2322: Type 'undefined' is not assignable to type 'string'. tests/cases/conformance/types/mapped/mappedTypeErrors.ts(106,17): error TS2345: Argument of type '{ c: boolean; }' is not assignable to parameter of type 'Pick<Foo, keyof Foo>'. Object literal may only specify known properties, and 'c' does not exist in type 'Pick<Foo, keyof Foo>'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(120,12): error TS2345: Argument of type '{ b: undefined; }' is not assignable to parameter of type 'Pick<Foo, keyof Foo>'. + Property 'a' is missing in type '{ b: undefined; }' but required in type 'Pick<Foo, keyof Foo>'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(121,12): error TS2345: Argument of type '{}' is not assignable to parameter of type 'Pick<Foo, keyof Foo>'. + Property 'a' is missing in type '{}' but required in type 'Pick<Foo, keyof Foo>'. tests/cases/conformance/types/mapped/mappedTypeErrors.ts(123,14): error TS2322: Type 'undefined' is not assignable to type 'string'. tests/cases/conformance/types/mapped/mappedTypeErrors.ts(124,14): error TS2345: Argument of type '{ c: boolean; }' is not assignable to parameter of type 'Pick<Foo, keyof Foo>'. Object literal may only specify known properties, and 'c' does not exist in type 'Pick<Foo, keyof Foo>'. @@ -36,7 +44,7 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(148,17): error TS2339: tests/cases/conformance/types/mapped/mappedTypeErrors.ts(152,17): error TS2339: Property 'foo' does not exist on type 'Record<K, number>'. -==== tests/cases/conformance/types/mapped/mappedTypeErrors.ts (27 errors) ==== +==== tests/cases/conformance/types/mapped/mappedTypeErrors.ts (31 errors) ==== interface Shape { name: string; width: number; @@ -184,12 +192,17 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(152,17): error TS2339: setState(foo, { a: "test", b: 43 }) setState(foo, { a: "hi" }); setState(foo, { b: undefined }); + ~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ b: undefined; }' is not assignable to parameter of type 'Pick<Foo, keyof Foo>'. +!!! error TS2345: Property 'a' is missing in type '{ b: undefined; }' but required in type 'Pick<Foo, keyof Foo>'. setState(foo, { }); + ~~~ +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'Pick<Foo, keyof Foo>'. +!!! error TS2345: Property 'a' is missing in type '{}' but required in type 'Pick<Foo, keyof Foo>'. setState(foo, foo); setState(foo, { a: undefined }); // Error ~ !!! error TS2322: Type 'undefined' is not assignable to type 'string'. -!!! related TS6500 tests/cases/conformance/types/mapped/mappedTypeErrors.ts:89:5: The expected type comes from property 'a' which is declared here on type 'Pick<Foo, "a">' setState(foo, { c: true }); // Error ~ !!! error TS2345: Argument of type '{ c: boolean; }' is not assignable to parameter of type 'Pick<Foo, keyof Foo>'. @@ -208,12 +221,17 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(152,17): error TS2339: c.setState({ a: "test", b: 43 }); c.setState({ a: "hi" }); c.setState({ b: undefined }); + ~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ b: undefined; }' is not assignable to parameter of type 'Pick<Foo, keyof Foo>'. +!!! error TS2345: Property 'a' is missing in type '{ b: undefined; }' but required in type 'Pick<Foo, keyof Foo>'. c.setState({ }); + ~~~ +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type 'Pick<Foo, keyof Foo>'. +!!! error TS2345: Property 'a' is missing in type '{}' but required in type 'Pick<Foo, keyof Foo>'. c.setState(foo); c.setState({ a: undefined }); // Error ~ !!! error TS2322: Type 'undefined' is not assignable to type 'string'. -!!! related TS6500 tests/cases/conformance/types/mapped/mappedTypeErrors.ts:89:5: The expected type comes from property 'a' which is declared here on type 'Pick<Foo, "a">' c.setState({ c: true }); // Error ~ !!! error TS2345: Argument of type '{ c: boolean; }' is not assignable to parameter of type 'Pick<Foo, keyof Foo>'. diff --git a/tests/baselines/reference/mappedTypeErrors.types b/tests/baselines/reference/mappedTypeErrors.types index d7d683313aeb7..4461891cc0cc2 100644 --- a/tests/baselines/reference/mappedTypeErrors.types +++ b/tests/baselines/reference/mappedTypeErrors.types @@ -41,25 +41,25 @@ type T03 = Record<Date, number>; // Error >T03 : {} type T10 = Pick<Shape, "name">; ->T10 : { name: string; } +>T10 : Pick<Shape, "name"> type T11 = Pick<Shape, "foo">; // Error ->T11 : { foo: unknown; } +>T11 : Pick<Shape, "foo"> type T12 = Pick<Shape, "name" | "foo">; // Error ->T12 : { name: string; foo: unknown; } +>T12 : Pick<Shape, "name" | "foo"> type T13 = Pick<Shape, keyof Named>; ->T13 : { name: string; } +>T13 : Pick<Shape, "name"> type T14 = Pick<Shape, keyof Point>; // Error ->T14 : { x: unknown; y: unknown; } +>T14 : Pick<Shape, keyof Point> type T15 = Pick<Shape, never>; ->T15 : {} +>T15 : Pick<Shape, never> type T16 = Pick<Shape, undefined>; // Error ->T16 : {} +>T16 : Pick<Shape, undefined> function f1<T>(x: T) { >f1 : <T>(x: T) => void @@ -263,17 +263,17 @@ function setState<T, K extends keyof T>(obj: T, props: Pick<T, K>) { >props : Pick<T, K> for (let k in props) { ->k : Extract<K, string> +>k : Extract<keyof Pick<T, K>, string> >props : Pick<T, K> obj[k] = props[k]; ->obj[k] = props[k] : Pick<T, K>[Extract<K, string>] ->obj[k] : T[Extract<K, string>] +>obj[k] = props[k] : Pick<T, K>[Extract<keyof Pick<T, K>, string>] +>obj[k] : T[Extract<keyof Pick<T, K>, string>] >obj : T ->k : Extract<K, string> ->props[k] : Pick<T, K>[Extract<K, string>] +>k : Extract<keyof Pick<T, K>, string> +>props[k] : Pick<T, K>[Extract<keyof Pick<T, K>, string>] >props : Pick<T, K> ->k : Extract<K, string> +>k : Extract<keyof Pick<T, K>, string> } } @@ -350,19 +350,19 @@ class C<T> { >props : Pick<T, K> for (let k in props) { ->k : Extract<K, string> +>k : Extract<keyof Pick<T, K>, string> >props : Pick<T, K> this.state[k] = props[k]; ->this.state[k] = props[k] : Pick<T, K>[Extract<K, string>] ->this.state[k] : T[Extract<K, string>] +>this.state[k] = props[k] : Pick<T, K>[Extract<keyof Pick<T, K>, string>] +>this.state[k] : T[Extract<keyof Pick<T, K>, string>] >this.state : T >this : this >state : T ->k : Extract<K, string> ->props[k] : Pick<T, K>[Extract<K, string>] +>k : Extract<keyof Pick<T, K>, string> +>props[k] : Pick<T, K>[Extract<keyof Pick<T, K>, string>] >props : Pick<T, K> ->k : Extract<K, string> +>k : Extract<keyof Pick<T, K>, string> } } } diff --git a/tests/baselines/reference/mappedTypeUnionConstraintInferences.types b/tests/baselines/reference/mappedTypeUnionConstraintInferences.types index 47a8ba7c99371..5acbbf1618a7d 100644 --- a/tests/baselines/reference/mappedTypeUnionConstraintInferences.types +++ b/tests/baselines/reference/mappedTypeUnionConstraintInferences.types @@ -1,6 +1,6 @@ === tests/cases/compiler/mappedTypeUnionConstraintInferences.ts === export declare 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 declare type PartialProperties<T, K extends keyof T> = Partial<Pick<T, K>> & Omit<T, K>; >PartialProperties : PartialProperties<T, K> diff --git a/tests/baselines/reference/mappedTypes2.errors.txt b/tests/baselines/reference/mappedTypes2.errors.txt new file mode 100644 index 0000000000000..f7cb36b3df2bc --- /dev/null +++ b/tests/baselines/reference/mappedTypes2.errors.txt @@ -0,0 +1,100 @@ +tests/cases/conformance/types/mapped/mappedTypes2.ts(7,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'x3' must be of type 'Pick<T, K>', but here has type '{ [P in K]: T[P]; }'. + + +==== tests/cases/conformance/types/mapped/mappedTypes2.ts (1 errors) ==== + function verifyLibTypes<T, K extends keyof T, U>() { + var x1: Partial<T>; + var x1: { [P in keyof T]?: T[P] }; + var x2: Readonly<T>; + var x2: { readonly [P in keyof T]: T[P] }; + var x3: Pick<T, K>; + var x3: { [P in K]: T[P] }; + ~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x3' must be of type 'Pick<T, K>', but here has type '{ [P in K]: T[P]; }'. +!!! related TS6203 tests/cases/conformance/types/mapped/mappedTypes2.ts:6:9: 'x3' was also declared here. + var x4: Record<K, U>; + var x4: { [P in K]: U }; + } + + type Proxy<T> = { + get(): T; + set(value: T): void; + } + + type Proxify<T> = { + [P in keyof T]: Proxy<T[P]>; + } + + type DeepReadonly<T> = { + readonly [P in keyof T]: DeepReadonly<T[P]>; + }; + + declare function assign<T>(obj: T, props: Partial<T>): void; + declare function freeze<T>(obj: T): Readonly<T>; + declare function pick<T, K extends keyof T>(obj: T, ...keys: K[]): Pick<T, K>; + declare function mapObject<K extends string, T, U>(obj: Record<K, T>, f: (x: T) => U): Record<K, U>; + declare function proxify<T>(obj: T): Proxify<T>; + + interface Point { + x: number; + y: number; + } + + interface Shape { + name: string; + width: number; + height: number; + location: Point; + } + + interface PartialShape { + name?: string; + width?: number; + height?: number; + location?: Point; + } + + interface ReadonlyShape { + readonly name: string; + readonly width: number; + readonly height: number; + readonly location: Point; + } + + function f0(s1: Shape, s2: Shape) { + assign(s1, { name: "circle" }); + assign(s2, { width: 10, height: 20 }); + } + + function f1(shape: Shape) { + var frozen: ReadonlyShape; + var frozen: Readonly<Shape>; + var frozen = freeze(shape); + } + + function f2(shape: Shape) { + var partial: PartialShape; + var partial: Partial<Shape>; + var partial: Partial<Shape> = {}; + } + + function f3(shape: Shape) { + const x = pick(shape, "name", "location"); // { name: string, location: Point } + } + + function f4() { + const rec = { foo: "hello", bar: "world", baz: "bye" }; + const lengths = mapObject(rec, s => s.length); // { foo: number, bar: number, baz: number } + } + + function f5(shape: Shape) { + const p = proxify(shape); + let name = p.name.get(); + p.width.set(42); + } + + function f6(shape: DeepReadonly<Shape>) { + let name = shape.name; // string + let location = shape.location; // DeepReadonly<Point> + let x = location.x; // number + } \ No newline at end of file diff --git a/tests/baselines/reference/omitTypeHelperModifiers01.symbols b/tests/baselines/reference/omitTypeHelperModifiers01.symbols index 39a3360678138..a5cc8be34f303 100644 --- a/tests/baselines/reference/omitTypeHelperModifiers01.symbols +++ b/tests/baselines/reference/omitTypeHelperModifiers01.symbols @@ -28,42 +28,42 @@ function f(x: B) { const b = x.b; >b : Symbol(b, Decl(omitTypeHelperModifiers01.ts, 10, 9)) ->x.b : Symbol(b, Decl(omitTypeHelperModifiers01.ts, 1, 14)) +>x.b : Symbol(b) >x : Symbol(x, Decl(omitTypeHelperModifiers01.ts, 9, 11)) ->b : Symbol(b, Decl(omitTypeHelperModifiers01.ts, 1, 14)) +>b : Symbol(b) x.b = "hello"; ->x.b : Symbol(b, Decl(omitTypeHelperModifiers01.ts, 1, 14)) +>x.b : Symbol(b) >x : Symbol(x, Decl(omitTypeHelperModifiers01.ts, 9, 11)) ->b : Symbol(b, Decl(omitTypeHelperModifiers01.ts, 1, 14)) +>b : Symbol(b) x.b = undefined; ->x.b : Symbol(b, Decl(omitTypeHelperModifiers01.ts, 1, 14)) +>x.b : Symbol(b) >x : Symbol(x, Decl(omitTypeHelperModifiers01.ts, 9, 11)) ->b : Symbol(b, Decl(omitTypeHelperModifiers01.ts, 1, 14)) +>b : Symbol(b) >undefined : Symbol(undefined) const c = x.c; >c : Symbol(c, Decl(omitTypeHelperModifiers01.ts, 14, 9)) ->x.c : Symbol(c, Decl(omitTypeHelperModifiers01.ts, 2, 15)) +>x.c : Symbol(c) >x : Symbol(x, Decl(omitTypeHelperModifiers01.ts, 9, 11)) ->c : Symbol(c, Decl(omitTypeHelperModifiers01.ts, 2, 15)) +>c : Symbol(c) x.c = true; ->x.c : Symbol(c, Decl(omitTypeHelperModifiers01.ts, 2, 15)) +>x.c : Symbol(c) >x : Symbol(x, Decl(omitTypeHelperModifiers01.ts, 9, 11)) ->c : Symbol(c, Decl(omitTypeHelperModifiers01.ts, 2, 15)) +>c : Symbol(c) const d = x.d; >d : Symbol(d, Decl(omitTypeHelperModifiers01.ts, 17, 9)) ->x.d : Symbol(d, Decl(omitTypeHelperModifiers01.ts, 3, 24)) +>x.d : Symbol(d) >x : Symbol(x, Decl(omitTypeHelperModifiers01.ts, 9, 11)) ->d : Symbol(d, Decl(omitTypeHelperModifiers01.ts, 3, 24)) +>d : Symbol(d) x.d = d; ->x.d : Symbol(d, Decl(omitTypeHelperModifiers01.ts, 3, 24)) +>x.d : Symbol(d) >x : Symbol(x, Decl(omitTypeHelperModifiers01.ts, 9, 11)) ->d : Symbol(d, Decl(omitTypeHelperModifiers01.ts, 3, 24)) +>d : Symbol(d) >d : Symbol(d, Decl(omitTypeHelperModifiers01.ts, 17, 9)) } diff --git a/tests/baselines/reference/omitTypeHelperModifiers01.types b/tests/baselines/reference/omitTypeHelperModifiers01.types index e956f06352f64..a3054e9bfe87c 100644 --- a/tests/baselines/reference/omitTypeHelperModifiers01.types +++ b/tests/baselines/reference/omitTypeHelperModifiers01.types @@ -17,55 +17,55 @@ type A = { }; type B = Omit<A, 'a'>; ->B : { b?: string | undefined; readonly c: boolean; d: unknown; } +>B : Omit<A, "a"> function f(x: B) { >f : (x: B) => void ->x : B +>x : Omit<A, "a"> const b = x.b; >b : string | undefined >x.b : string | undefined ->x : B +>x : Omit<A, "a"> >b : string | undefined x.b = "hello"; >x.b = "hello" : "hello" >x.b : string | undefined ->x : B +>x : Omit<A, "a"> >b : string | undefined >"hello" : "hello" x.b = undefined; >x.b = undefined : undefined >x.b : string | undefined ->x : B +>x : Omit<A, "a"> >b : string | undefined >undefined : undefined const c = x.c; >c : boolean >x.c : boolean ->x : B +>x : Omit<A, "a"> >c : boolean x.c = true; >x.c = true : true >x.c : any ->x : B +>x : Omit<A, "a"> >c : any >true : true const d = x.d; >d : unknown >x.d : unknown ->x : B +>x : Omit<A, "a"> >d : unknown x.d = d; >x.d = d : unknown >x.d : unknown ->x : B +>x : Omit<A, "a"> >d : unknown >d : unknown } diff --git a/tests/baselines/reference/omitTypeTestErrors01.errors.txt b/tests/baselines/reference/omitTypeTestErrors01.errors.txt index 9a363e767951d..6b65e292b55f4 100644 --- a/tests/baselines/reference/omitTypeTestErrors01.errors.txt +++ b/tests/baselines/reference/omitTypeTestErrors01.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/omitTypeTestErrors01.ts(11,16): error TS2339: Property 'c' does not exist on type 'Bar'. -tests/cases/compiler/omitTypeTestErrors01.ts(15,16): error TS2339: Property 'b' does not exist on type 'Baz'. +tests/cases/compiler/omitTypeTestErrors01.ts(11,16): error TS2339: Property 'c' does not exist on type 'Omit<Foo, "c">'. +tests/cases/compiler/omitTypeTestErrors01.ts(15,16): error TS2339: Property 'b' does not exist on type 'Omit<Foo, "c" | "b">'. ==== tests/cases/compiler/omitTypeTestErrors01.ts (2 errors) ==== @@ -15,13 +15,13 @@ tests/cases/compiler/omitTypeTestErrors01.ts(15,16): error TS2339: Property 'b' export function getBarC(bar: Bar) { return bar.c; ~ -!!! error TS2339: Property 'c' does not exist on type 'Bar'. +!!! error TS2339: Property 'c' does not exist on type 'Omit<Foo, "c">'. } export function getBazB(baz: Baz) { return baz.b; ~ -!!! error TS2339: Property 'b' does not exist on type 'Baz'. +!!! error TS2339: Property 'b' does not exist on type 'Omit<Foo, "c" | "b">'. } \ No newline at end of file diff --git a/tests/baselines/reference/omitTypeTestErrors01.types b/tests/baselines/reference/omitTypeTestErrors01.types index f341e33cc0640..5a5935126682e 100644 --- a/tests/baselines/reference/omitTypeTestErrors01.types +++ b/tests/baselines/reference/omitTypeTestErrors01.types @@ -11,28 +11,28 @@ interface Foo { } export type Bar = Omit<Foo, "c">; ->Bar : { a: string; b: number; } +>Bar : Omit<Foo, "c"> export type Baz = Omit<Foo, "b" | "c">; ->Baz : { a: string; } +>Baz : Omit<Foo, "c" | "b"> export function getBarC(bar: Bar) { >getBarC : (bar: Bar) => any ->bar : Bar +>bar : Omit<Foo, "c"> return bar.c; >bar.c : any ->bar : Bar +>bar : Omit<Foo, "c"> >c : any } export function getBazB(baz: Baz) { >getBazB : (baz: Baz) => any ->baz : Baz +>baz : Omit<Foo, "c" | "b"> return baz.b; >baz.b : any ->baz : Baz +>baz : Omit<Foo, "c" | "b"> >b : any } diff --git a/tests/baselines/reference/omitTypeTests01.symbols b/tests/baselines/reference/omitTypeTests01.symbols index d614f65daff03..93b492917855a 100644 --- a/tests/baselines/reference/omitTypeTests01.symbols +++ b/tests/baselines/reference/omitTypeTests01.symbols @@ -28,9 +28,9 @@ export function getBarA(bar: Bar) { >Bar : Symbol(Bar, Decl(omitTypeTests01.ts, 4, 1)) return bar.a; ->bar.a : Symbol(a, Decl(omitTypeTests01.ts, 0, 15)) +>bar.a : Symbol(a) >bar : Symbol(bar, Decl(omitTypeTests01.ts, 9, 24)) ->a : Symbol(a, Decl(omitTypeTests01.ts, 0, 15)) +>a : Symbol(a) } export function getBazA(baz: Baz) { @@ -39,9 +39,9 @@ export function getBazA(baz: Baz) { >Baz : Symbol(Baz, Decl(omitTypeTests01.ts, 6, 33)) return baz.a; ->baz.a : Symbol(a, Decl(omitTypeTests01.ts, 0, 15)) +>baz.a : Symbol(a) >baz : Symbol(baz, Decl(omitTypeTests01.ts, 13, 24)) ->a : Symbol(a, Decl(omitTypeTests01.ts, 0, 15)) +>a : Symbol(a) } diff --git a/tests/baselines/reference/omitTypeTests01.types b/tests/baselines/reference/omitTypeTests01.types index 6a270844af5b5..f0f5b0627a69a 100644 --- a/tests/baselines/reference/omitTypeTests01.types +++ b/tests/baselines/reference/omitTypeTests01.types @@ -11,28 +11,28 @@ interface Foo { } export type Bar = Omit<Foo, "c">; ->Bar : { a: string; b: number; } +>Bar : Omit<Foo, "c"> export type Baz = Omit<Foo, "b" | "c">; ->Baz : { a: string; } +>Baz : Omit<Foo, "c" | "b"> export function getBarA(bar: Bar) { >getBarA : (bar: Bar) => string ->bar : Bar +>bar : Omit<Foo, "c"> return bar.a; >bar.a : string ->bar : Bar +>bar : Omit<Foo, "c"> >a : string } export function getBazA(baz: Baz) { >getBazA : (baz: Baz) => string ->baz : Baz +>baz : Omit<Foo, "c" | "b"> return baz.a; >baz.a : string ->baz : Baz +>baz : Omit<Foo, "c" | "b"> >a : string } diff --git a/tests/baselines/reference/reactDefaultPropsInferenceSuccess.errors.txt b/tests/baselines/reference/reactDefaultPropsInferenceSuccess.errors.txt index 335f0febc862f..9f160a7775f31 100644 --- a/tests/baselines/reference/reactDefaultPropsInferenceSuccess.errors.txt +++ b/tests/baselines/reference/reactDefaultPropsInferenceSuccess.errors.txt @@ -56,8 +56,6 @@ tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx(64,37): error TS2769: !!! error TS2769: Type 'void' is not assignable to type 'boolean'. !!! error TS2769: Overload 2 of 2, '(props: Props, context?: any): FieldFeedback<Props>', gave the following error. !!! error TS2769: Type '(value: string) => void' is not assignable to type '"a" | "b" | ((value: string) => boolean) | undefined'. -!!! related TS6500 tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx:6:3: The expected type comes from property 'when' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<FieldFeedback<Props>> & Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, "children" | "error"> & Partial<Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, "when">> & Partial<Pick<{ when: () => boolean; }, never>>' -!!! related TS6500 tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx:6:3: The expected type comes from property 'when' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<FieldFeedback<Props>> & Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, "children" | "error"> & Partial<Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, "when">> & Partial<Pick<{ when: () => boolean; }, never>>' class FieldFeedbackBeta<P extends Props = BaseProps> extends React.Component<P> { static defaultProps: BaseProps = { @@ -82,8 +80,6 @@ tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx(64,37): error TS2769: !!! error TS2769: Type 'void' is not assignable to type 'boolean'. !!! error TS2769: Overload 2 of 2, '(props: Props, context?: any): FieldFeedbackBeta<Props>', gave the following error. !!! error TS2769: Type '(value: string) => void' is not assignable to type '"a" | "b" | ((value: string) => boolean) | undefined'. -!!! related TS6500 tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx:6:3: The expected type comes from property 'when' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<FieldFeedbackBeta<Props>> & Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, "children"> & Partial<Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, keyof Props>> & Partial<Pick<BaseProps, never>>' -!!! related TS6500 tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx:6:3: The expected type comes from property 'when' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<FieldFeedbackBeta<Props>> & Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, "children"> & Partial<Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, keyof Props>> & Partial<Pick<BaseProps, never>>' interface MyPropsProps extends Props { when: (value: string) => boolean; @@ -112,8 +108,6 @@ tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx(64,37): error TS2769: !!! error TS2769: Type 'void' is not assignable to type 'boolean'. !!! error TS2769: Overload 2 of 2, '(props: MyPropsProps, context?: any): FieldFeedback2<MyPropsProps>', gave the following error. !!! error TS2769: Type '(value: string) => void' is not assignable to type '(value: string) => boolean'. -!!! related TS6500 tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx:46:3: The expected type comes from property 'when' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<FieldFeedback2<MyPropsProps>> & Pick<Readonly<{ children?: ReactNode; }> & Readonly<MyPropsProps>, "children" | "error"> & Partial<Pick<Readonly<{ children?: ReactNode; }> & Readonly<MyPropsProps>, "when">> & Partial<Pick<{ when: () => boolean; }, never>>' -!!! related TS6500 tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx:46:3: The expected type comes from property 'when' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<FieldFeedback2<MyPropsProps>> & Pick<Readonly<{ children?: ReactNode; }> & Readonly<MyPropsProps>, "children" | "error"> & Partial<Pick<Readonly<{ children?: ReactNode; }> & Readonly<MyPropsProps>, "when">> & Partial<Pick<{ when: () => boolean; }, never>>' // OK const Test5 = () => <FieldFeedback2 />; diff --git a/tests/baselines/reference/reactReduxLikeDeferredInferenceAllowsAssignment.types b/tests/baselines/reference/reactReduxLikeDeferredInferenceAllowsAssignment.types index 680071c7ab3a5..f2ff798f2e1f3 100644 --- a/tests/baselines/reference/reactReduxLikeDeferredInferenceAllowsAssignment.types +++ b/tests/baselines/reference/reactReduxLikeDeferredInferenceAllowsAssignment.types @@ -119,7 +119,7 @@ type Matching<InjectedProps, DecorationTargetProps> = { }; 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 InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> = < >InferableComponentEnhancerWithProps : InferableComponentEnhancerWithProps<TInjectedProps, TNeedsProps> @@ -262,8 +262,8 @@ type Q = HandleThunkActionCreator<typeof simpleAction>; >simpleAction : (payload: boolean) => { type: string; payload: boolean; } const Test1 = connect( ->Test1 : ConnectedComponentClass<typeof TestComponent, Omit<TestComponentProps, "simpleAction" | "thunkAction">> ->connect( null, mapDispatchToProps)(TestComponent) : ConnectedComponentClass<typeof TestComponent, Omit<TestComponentProps, "simpleAction" | "thunkAction">> +>Test1 : ConnectedComponentClass<typeof TestComponent, Pick<TestComponentProps, "foo">> +>connect( null, mapDispatchToProps)(TestComponent) : ConnectedComponentClass<typeof TestComponent, Pick<TestComponentProps, "foo">> >connect( null, mapDispatchToProps) : InferableComponentEnhancerWithProps<{ simpleAction: (payload: boolean) => { type: string; payload: boolean; }; thunkAction: (param1: number, param2: string) => Promise<string>; }, {}> >connect : <no_state = {}, TDispatchProps = {}, TOwnProps = {}>(mapStateToProps: null | undefined, mapDispatchToProps: TDispatchProps) => InferableComponentEnhancerWithProps<ResolveThunks<TDispatchProps>, TOwnProps> diff --git a/tests/baselines/reference/staticIndexSignature5.types b/tests/baselines/reference/staticIndexSignature5.types index 2f3ea91f8cfc2..6f47d770cfba0 100644 --- a/tests/baselines/reference/staticIndexSignature5.types +++ b/tests/baselines/reference/staticIndexSignature5.types @@ -38,16 +38,16 @@ type TE = keyof typeof B; >B : typeof B type TF = Pick<typeof B, number> ->TF : { [x: number]: 42 | 233; } +>TF : Pick<typeof B, number> >B : typeof B type TFI = Pick<I, number> ->TFI : { [x: number]: 42 | 233; } +>TFI : Pick<I, number> type TG = Omit<typeof B, number> ->TG : { [x: string]: number; } +>TG : Omit<typeof B, number> >B : typeof B type TGI = Omit<I, number> ->TGI : { [x: string]: number; } +>TGI : Omit<I, number> diff --git a/tests/baselines/reference/styledComponentsInstantiaionLimitNotReached.types b/tests/baselines/reference/styledComponentsInstantiaionLimitNotReached.types index efce2c28ffdf4..f4835cbd82a0b 100644 --- a/tests/baselines/reference/styledComponentsInstantiaionLimitNotReached.types +++ b/tests/baselines/reference/styledComponentsInstantiaionLimitNotReached.types @@ -264,7 +264,7 @@ type WithOptionalTheme<P extends { theme?: T }, T> = Omit<P, 'theme'> & { }; type ForwardRefExoticBase<P> = Pick<React.ForwardRefExoticComponent<P>, keyof React.ForwardRefExoticComponent<any>>; ->ForwardRefExoticBase : ForwardRefExoticBase<P> +>ForwardRefExoticBase : Pick<React.ForwardRefExoticComponent<P>, keyof React.ForwardRefExoticComponent<any>> >React : any >React : any diff --git a/tests/baselines/reference/tupleTypes.types b/tests/baselines/reference/tupleTypes.types index ba2654609c181..d02ac9ac0475b 100644 --- a/tests/baselines/reference/tupleTypes.types +++ b/tests/baselines/reference/tupleTypes.types @@ -227,15 +227,15 @@ a3 = a2; >a2 : [number, number] type B = Pick<[number], 'length'>; ->B : { length: 1; } +>B : Pick<[number], "length"> declare const b: B; ->b : B +>b : Pick<[number], "length"> b.length = 0; // Error >b.length = 0 : 0 >b.length : 1 ->b : B +>b : Pick<[number], "length"> >length : 1 >0 : 0 diff --git a/tests/cases/fourslash/completionListInheritedClassMembers.ts b/tests/cases/fourslash/completionListInheritedClassMembers.ts index fcfac396c4105..3a6cef93ccfa8 100644 --- a/tests/cases/fourslash/completionListInheritedClassMembers.ts +++ b/tests/cases/fourslash/completionListInheritedClassMembers.ts @@ -18,7 +18,7 @@ ////} ////export class A2 {} //// -////type T3 = Pick<I, "m3"> +////type T3 = { "m3": I["m3"] }; ////export interface A3 extends T3 { //// m1(): void; ////}