-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Fixed an issue with not being able to use mapped type over union constraint as rest param #49947
Merged
weswigham
merged 7 commits into
microsoft:main
from
Andarist:fix/rest-param-using-mapped-type-over-union-constraint
Mar 20, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6554965
Fixed an issue with not being able to use mapped type over union cons…
Andarist f94efbd
Fixed an issue when targeting non-readonly arrays with source being a…
Andarist ce8483c
Merge remote-tracking branch 'origin/main' into fix/rest-param-using-…
Andarist 29d4bb9
Merge remote-tracking branch 'origin/main' into fix/rest-param-using-…
Andarist 940e1ad
Bring back resolving apparent type for mapped types with tuple constr…
Andarist 88764fe
Merge remote-tracking branch 'origin/main' into fix/rest-param-using-…
Andarist 8e78414
Add extra test cases
Andarist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
tests/baselines/reference/mappedTypeTupleConstraintAssignability.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
=== tests/cases/compiler/mappedTypeTupleConstraintAssignability.ts === | ||
// https://github.com/microsoft/TypeScript/issues/53359#issuecomment-1475390594 | ||
|
||
type Writeable<T> = { -readonly [P in keyof T]: T[P] }; | ||
>Writeable : Symbol(Writeable, Decl(mappedTypeTupleConstraintAssignability.ts, 0, 0)) | ||
>T : Symbol(T, Decl(mappedTypeTupleConstraintAssignability.ts, 2, 15)) | ||
>P : Symbol(P, Decl(mappedTypeTupleConstraintAssignability.ts, 2, 33)) | ||
>T : Symbol(T, Decl(mappedTypeTupleConstraintAssignability.ts, 2, 15)) | ||
>T : Symbol(T, Decl(mappedTypeTupleConstraintAssignability.ts, 2, 15)) | ||
>P : Symbol(P, Decl(mappedTypeTupleConstraintAssignability.ts, 2, 33)) | ||
|
||
type EnumValues = [string, ...string[]]; | ||
>EnumValues : Symbol(EnumValues, Decl(mappedTypeTupleConstraintAssignability.ts, 2, 55)) | ||
|
||
type Values<T extends EnumValues> = { [k in T[number]]: k; }; | ||
>Values : Symbol(Values, Decl(mappedTypeTupleConstraintAssignability.ts, 3, 40)) | ||
>T : Symbol(T, Decl(mappedTypeTupleConstraintAssignability.ts, 4, 12)) | ||
>EnumValues : Symbol(EnumValues, Decl(mappedTypeTupleConstraintAssignability.ts, 2, 55)) | ||
>k : Symbol(k, Decl(mappedTypeTupleConstraintAssignability.ts, 4, 39)) | ||
>T : Symbol(T, Decl(mappedTypeTupleConstraintAssignability.ts, 4, 12)) | ||
>k : Symbol(k, Decl(mappedTypeTupleConstraintAssignability.ts, 4, 39)) | ||
|
||
declare class ZodEnum<T extends [string, ...string[]]> { | ||
>ZodEnum : Symbol(ZodEnum, Decl(mappedTypeTupleConstraintAssignability.ts, 4, 61)) | ||
>T : Symbol(T, Decl(mappedTypeTupleConstraintAssignability.ts, 6, 22)) | ||
|
||
get enum(): Values<T> | ||
>enum : Symbol(ZodEnum.enum, Decl(mappedTypeTupleConstraintAssignability.ts, 6, 56)) | ||
>Values : Symbol(Values, Decl(mappedTypeTupleConstraintAssignability.ts, 3, 40)) | ||
>T : Symbol(T, Decl(mappedTypeTupleConstraintAssignability.ts, 6, 22)) | ||
} | ||
|
||
declare function createZodEnum<U extends string, T extends Readonly<[U, ...U[]]>>(values: T): ZodEnum<Writeable<T>>; | ||
>createZodEnum : Symbol(createZodEnum, Decl(mappedTypeTupleConstraintAssignability.ts, 8, 1)) | ||
>U : Symbol(U, Decl(mappedTypeTupleConstraintAssignability.ts, 10, 31)) | ||
>T : Symbol(T, Decl(mappedTypeTupleConstraintAssignability.ts, 10, 48)) | ||
>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --)) | ||
>U : Symbol(U, Decl(mappedTypeTupleConstraintAssignability.ts, 10, 31)) | ||
>U : Symbol(U, Decl(mappedTypeTupleConstraintAssignability.ts, 10, 31)) | ||
>values : Symbol(values, Decl(mappedTypeTupleConstraintAssignability.ts, 10, 82)) | ||
>T : Symbol(T, Decl(mappedTypeTupleConstraintAssignability.ts, 10, 48)) | ||
>ZodEnum : Symbol(ZodEnum, Decl(mappedTypeTupleConstraintAssignability.ts, 4, 61)) | ||
>Writeable : Symbol(Writeable, Decl(mappedTypeTupleConstraintAssignability.ts, 0, 0)) | ||
>T : Symbol(T, Decl(mappedTypeTupleConstraintAssignability.ts, 10, 48)) | ||
|
||
// https://github.com/microsoft/TypeScript/issues/53359#issuecomment-1475390607 | ||
|
||
type Maybe<T> = T | null | undefined; | ||
>Maybe : Symbol(Maybe, Decl(mappedTypeTupleConstraintAssignability.ts, 10, 116)) | ||
>T : Symbol(T, Decl(mappedTypeTupleConstraintAssignability.ts, 14, 11)) | ||
>T : Symbol(T, Decl(mappedTypeTupleConstraintAssignability.ts, 14, 11)) | ||
|
||
type AnyTuple = [unknown, ...unknown[]]; | ||
>AnyTuple : Symbol(AnyTuple, Decl(mappedTypeTupleConstraintAssignability.ts, 14, 37)) | ||
|
||
type AnyObject = { [k: string]: any }; | ||
>AnyObject : Symbol(AnyObject, Decl(mappedTypeTupleConstraintAssignability.ts, 15, 40)) | ||
>k : Symbol(k, Decl(mappedTypeTupleConstraintAssignability.ts, 16, 20)) | ||
|
||
type Flags = "s" | "d" | ""; | ||
>Flags : Symbol(Flags, Decl(mappedTypeTupleConstraintAssignability.ts, 16, 38)) | ||
|
||
interface ISchema<T, C = any, F extends Flags = any, D = any> { | ||
>ISchema : Symbol(ISchema, Decl(mappedTypeTupleConstraintAssignability.ts, 17, 28)) | ||
>T : Symbol(T, Decl(mappedTypeTupleConstraintAssignability.ts, 19, 18)) | ||
>C : Symbol(C, Decl(mappedTypeTupleConstraintAssignability.ts, 19, 20)) | ||
>F : Symbol(F, Decl(mappedTypeTupleConstraintAssignability.ts, 19, 29)) | ||
>Flags : Symbol(Flags, Decl(mappedTypeTupleConstraintAssignability.ts, 16, 38)) | ||
>D : Symbol(D, Decl(mappedTypeTupleConstraintAssignability.ts, 19, 52)) | ||
|
||
__flags: F; | ||
>__flags : Symbol(ISchema.__flags, Decl(mappedTypeTupleConstraintAssignability.ts, 19, 63)) | ||
>F : Symbol(F, Decl(mappedTypeTupleConstraintAssignability.ts, 19, 29)) | ||
|
||
__context: C; | ||
>__context : Symbol(ISchema.__context, Decl(mappedTypeTupleConstraintAssignability.ts, 20, 13)) | ||
>C : Symbol(C, Decl(mappedTypeTupleConstraintAssignability.ts, 19, 20)) | ||
|
||
__outputType: T; | ||
>__outputType : Symbol(ISchema.__outputType, Decl(mappedTypeTupleConstraintAssignability.ts, 21, 15)) | ||
>T : Symbol(T, Decl(mappedTypeTupleConstraintAssignability.ts, 19, 18)) | ||
|
||
__default: D; | ||
>__default : Symbol(ISchema.__default, Decl(mappedTypeTupleConstraintAssignability.ts, 22, 18)) | ||
>D : Symbol(D, Decl(mappedTypeTupleConstraintAssignability.ts, 19, 52)) | ||
} | ||
|
||
declare class TupleSchema< | ||
>TupleSchema : Symbol(TupleSchema, Decl(mappedTypeTupleConstraintAssignability.ts, 24, 1)) | ||
|
||
TType extends Maybe<AnyTuple> = AnyTuple | undefined, | ||
>TType : Symbol(TType, Decl(mappedTypeTupleConstraintAssignability.ts, 26, 26)) | ||
>Maybe : Symbol(Maybe, Decl(mappedTypeTupleConstraintAssignability.ts, 10, 116)) | ||
>AnyTuple : Symbol(AnyTuple, Decl(mappedTypeTupleConstraintAssignability.ts, 14, 37)) | ||
>AnyTuple : Symbol(AnyTuple, Decl(mappedTypeTupleConstraintAssignability.ts, 14, 37)) | ||
|
||
TContext = AnyObject, | ||
>TContext : Symbol(TContext, Decl(mappedTypeTupleConstraintAssignability.ts, 27, 55)) | ||
>AnyObject : Symbol(AnyObject, Decl(mappedTypeTupleConstraintAssignability.ts, 15, 40)) | ||
|
||
TDefault = undefined, | ||
>TDefault : Symbol(TDefault, Decl(mappedTypeTupleConstraintAssignability.ts, 28, 23)) | ||
|
||
TFlags extends Flags = "" | ||
>TFlags : Symbol(TFlags, Decl(mappedTypeTupleConstraintAssignability.ts, 29, 23)) | ||
>Flags : Symbol(Flags, Decl(mappedTypeTupleConstraintAssignability.ts, 16, 38)) | ||
|
||
> { | ||
constructor(schemas: [ISchema<any>, ...ISchema<any>[]]); | ||
>schemas : Symbol(schemas, Decl(mappedTypeTupleConstraintAssignability.ts, 32, 14)) | ||
>ISchema : Symbol(ISchema, Decl(mappedTypeTupleConstraintAssignability.ts, 17, 28)) | ||
>ISchema : Symbol(ISchema, Decl(mappedTypeTupleConstraintAssignability.ts, 17, 28)) | ||
} | ||
|
||
export function create<T extends AnyTuple>(schemas: { | ||
>create : Symbol(create, Decl(mappedTypeTupleConstraintAssignability.ts, 33, 1)) | ||
>T : Symbol(T, Decl(mappedTypeTupleConstraintAssignability.ts, 35, 23)) | ||
>AnyTuple : Symbol(AnyTuple, Decl(mappedTypeTupleConstraintAssignability.ts, 14, 37)) | ||
>schemas : Symbol(schemas, Decl(mappedTypeTupleConstraintAssignability.ts, 35, 43)) | ||
|
||
[K in keyof T]: ISchema<T[K]>; | ||
>K : Symbol(K, Decl(mappedTypeTupleConstraintAssignability.ts, 36, 3)) | ||
>T : Symbol(T, Decl(mappedTypeTupleConstraintAssignability.ts, 35, 23)) | ||
>ISchema : Symbol(ISchema, Decl(mappedTypeTupleConstraintAssignability.ts, 17, 28)) | ||
>T : Symbol(T, Decl(mappedTypeTupleConstraintAssignability.ts, 35, 23)) | ||
>K : Symbol(K, Decl(mappedTypeTupleConstraintAssignability.ts, 36, 3)) | ||
|
||
}) { | ||
return new TupleSchema<T | undefined>(schemas); | ||
>TupleSchema : Symbol(TupleSchema, Decl(mappedTypeTupleConstraintAssignability.ts, 24, 1)) | ||
>T : Symbol(T, Decl(mappedTypeTupleConstraintAssignability.ts, 35, 23)) | ||
>schemas : Symbol(schemas, Decl(mappedTypeTupleConstraintAssignability.ts, 35, 43)) | ||
} | ||
|
76 changes: 76 additions & 0 deletions
76
tests/baselines/reference/mappedTypeTupleConstraintAssignability.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
=== tests/cases/compiler/mappedTypeTupleConstraintAssignability.ts === | ||
// https://github.com/microsoft/TypeScript/issues/53359#issuecomment-1475390594 | ||
|
||
type Writeable<T> = { -readonly [P in keyof T]: T[P] }; | ||
>Writeable : Writeable<T> | ||
|
||
type EnumValues = [string, ...string[]]; | ||
>EnumValues : [string, ...string[]] | ||
|
||
type Values<T extends EnumValues> = { [k in T[number]]: k; }; | ||
>Values : Values<T> | ||
|
||
declare class ZodEnum<T extends [string, ...string[]]> { | ||
>ZodEnum : ZodEnum<T> | ||
|
||
get enum(): Values<T> | ||
>enum : Values<T> | ||
} | ||
|
||
declare function createZodEnum<U extends string, T extends Readonly<[U, ...U[]]>>(values: T): ZodEnum<Writeable<T>>; | ||
>createZodEnum : <U extends string, T extends readonly [U, ...U[]]>(values: T) => ZodEnum<Writeable<T>> | ||
>values : T | ||
|
||
// https://github.com/microsoft/TypeScript/issues/53359#issuecomment-1475390607 | ||
|
||
type Maybe<T> = T | null | undefined; | ||
>Maybe : Maybe<T> | ||
|
||
type AnyTuple = [unknown, ...unknown[]]; | ||
>AnyTuple : [unknown, ...unknown[]] | ||
|
||
type AnyObject = { [k: string]: any }; | ||
>AnyObject : { [k: string]: any; } | ||
>k : string | ||
|
||
type Flags = "s" | "d" | ""; | ||
>Flags : "" | "s" | "d" | ||
|
||
interface ISchema<T, C = any, F extends Flags = any, D = any> { | ||
__flags: F; | ||
>__flags : F | ||
|
||
__context: C; | ||
>__context : C | ||
|
||
__outputType: T; | ||
>__outputType : T | ||
|
||
__default: D; | ||
>__default : D | ||
} | ||
|
||
declare class TupleSchema< | ||
>TupleSchema : TupleSchema<TType, TContext, TDefault, TFlags> | ||
|
||
TType extends Maybe<AnyTuple> = AnyTuple | undefined, | ||
TContext = AnyObject, | ||
TDefault = undefined, | ||
TFlags extends Flags = "" | ||
> { | ||
constructor(schemas: [ISchema<any>, ...ISchema<any>[]]); | ||
>schemas : [ISchema<any, any, any, any>, ...ISchema<any, any, any, any>[]] | ||
} | ||
|
||
export function create<T extends AnyTuple>(schemas: { | ||
>create : <T extends AnyTuple>(schemas: { [K in keyof T]: ISchema<T[K], any, any, any>; }) => TupleSchema<T | undefined, AnyObject, undefined, ""> | ||
>schemas : { [K in keyof T]: ISchema<T[K], any, any, any>; } | ||
|
||
[K in keyof T]: ISchema<T[K]>; | ||
}) { | ||
return new TupleSchema<T | undefined>(schemas); | ||
>new TupleSchema<T | undefined>(schemas) : TupleSchema<T | undefined, AnyObject, undefined, ""> | ||
>TupleSchema : typeof TupleSchema | ||
>schemas : { [K in keyof T]: ISchema<T[K], any, any, any>; } | ||
} | ||
|
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/mappedTypeUnionConstrainTupleTreatedAsArrayLike.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
tests/cases/compiler/mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts(9,9): error TS2322: Type 'HomomorphicMappedType<T>' is not assignable to type 'any[]'. | ||
|
||
|
||
==== tests/cases/compiler/mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts (1 errors) ==== | ||
type HomomorphicMappedType<T> = { [P in keyof T]: T[P] extends string ? boolean : null } | ||
|
||
function test1<T extends [number] | [string]>(args: T) { | ||
const arr: any[] = [] as HomomorphicMappedType<T> | ||
const arr2: readonly any[] = [] as HomomorphicMappedType<T> | ||
} | ||
|
||
function test2<T extends [number] | readonly [string]>(args: T) { | ||
const arr: any[] = [] as HomomorphicMappedType<T> // error | ||
~~~ | ||
!!! error TS2322: Type 'HomomorphicMappedType<T>' is not assignable to type 'any[]'. | ||
const arr2: readonly any[] = [] as HomomorphicMappedType<T> | ||
} | ||
|
43 changes: 43 additions & 0 deletions
43
tests/baselines/reference/mappedTypeUnionConstrainTupleTreatedAsArrayLike.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
=== tests/cases/compiler/mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts === | ||
type HomomorphicMappedType<T> = { [P in keyof T]: T[P] extends string ? boolean : null } | ||
>HomomorphicMappedType : Symbol(HomomorphicMappedType, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 0, 0)) | ||
>T : Symbol(T, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 0, 27)) | ||
>P : Symbol(P, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 0, 35)) | ||
>T : Symbol(T, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 0, 27)) | ||
>T : Symbol(T, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 0, 27)) | ||
>P : Symbol(P, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 0, 35)) | ||
|
||
function test1<T extends [number] | [string]>(args: T) { | ||
>test1 : Symbol(test1, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 0, 88)) | ||
>T : Symbol(T, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 2, 15)) | ||
>args : Symbol(args, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 2, 46)) | ||
>T : Symbol(T, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 2, 15)) | ||
|
||
const arr: any[] = [] as HomomorphicMappedType<T> | ||
>arr : Symbol(arr, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 3, 7)) | ||
>HomomorphicMappedType : Symbol(HomomorphicMappedType, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 0, 0)) | ||
>T : Symbol(T, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 2, 15)) | ||
|
||
const arr2: readonly any[] = [] as HomomorphicMappedType<T> | ||
>arr2 : Symbol(arr2, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 4, 7)) | ||
>HomomorphicMappedType : Symbol(HomomorphicMappedType, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 0, 0)) | ||
>T : Symbol(T, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 2, 15)) | ||
} | ||
|
||
function test2<T extends [number] | readonly [string]>(args: T) { | ||
>test2 : Symbol(test2, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 5, 1)) | ||
>T : Symbol(T, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 7, 15)) | ||
>args : Symbol(args, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 7, 55)) | ||
>T : Symbol(T, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 7, 15)) | ||
|
||
const arr: any[] = [] as HomomorphicMappedType<T> // error | ||
>arr : Symbol(arr, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 8, 7)) | ||
>HomomorphicMappedType : Symbol(HomomorphicMappedType, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 0, 0)) | ||
>T : Symbol(T, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 7, 15)) | ||
|
||
const arr2: readonly any[] = [] as HomomorphicMappedType<T> | ||
>arr2 : Symbol(arr2, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 9, 7)) | ||
>HomomorphicMappedType : Symbol(HomomorphicMappedType, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 0, 0)) | ||
>T : Symbol(T, Decl(mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts, 7, 15)) | ||
} | ||
|
34 changes: 34 additions & 0 deletions
34
tests/baselines/reference/mappedTypeUnionConstrainTupleTreatedAsArrayLike.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
=== tests/cases/compiler/mappedTypeUnionConstrainTupleTreatedAsArrayLike.ts === | ||
type HomomorphicMappedType<T> = { [P in keyof T]: T[P] extends string ? boolean : null } | ||
>HomomorphicMappedType : HomomorphicMappedType<T> | ||
|
||
function test1<T extends [number] | [string]>(args: T) { | ||
>test1 : <T extends [number] | [string]>(args: T) => void | ||
>args : T | ||
|
||
const arr: any[] = [] as HomomorphicMappedType<T> | ||
>arr : any[] | ||
>[] as HomomorphicMappedType<T> : HomomorphicMappedType<T> | ||
>[] : [] | ||
|
||
const arr2: readonly any[] = [] as HomomorphicMappedType<T> | ||
>arr2 : readonly any[] | ||
>[] as HomomorphicMappedType<T> : HomomorphicMappedType<T> | ||
>[] : [] | ||
} | ||
|
||
function test2<T extends [number] | readonly [string]>(args: T) { | ||
>test2 : <T extends [number] | readonly [string]>(args: T) => void | ||
>args : T | ||
|
||
const arr: any[] = [] as HomomorphicMappedType<T> // error | ||
>arr : any[] | ||
>[] as HomomorphicMappedType<T> : HomomorphicMappedType<T> | ||
>[] : [] | ||
|
||
const arr2: readonly any[] = [] as HomomorphicMappedType<T> | ||
>arr2 : readonly any[] | ||
>[] as HomomorphicMappedType<T> : HomomorphicMappedType<T> | ||
>[] : [] | ||
} | ||
|
27 changes: 27 additions & 0 deletions
27
tests/baselines/reference/restParamUsingMappedTypeOverUnionConstraint.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
=== tests/cases/compiler/restParamUsingMappedTypeOverUnionConstraint.ts === | ||
// repro 29919#issuecomment-470948453 | ||
|
||
type HomomorphicMappedType<T> = { [P in keyof T]: T[P] extends string ? boolean : null } | ||
>HomomorphicMappedType : Symbol(HomomorphicMappedType, Decl(restParamUsingMappedTypeOverUnionConstraint.ts, 0, 0)) | ||
>T : Symbol(T, Decl(restParamUsingMappedTypeOverUnionConstraint.ts, 2, 27)) | ||
>P : Symbol(P, Decl(restParamUsingMappedTypeOverUnionConstraint.ts, 2, 35)) | ||
>T : Symbol(T, Decl(restParamUsingMappedTypeOverUnionConstraint.ts, 2, 27)) | ||
>T : Symbol(T, Decl(restParamUsingMappedTypeOverUnionConstraint.ts, 2, 27)) | ||
>P : Symbol(P, Decl(restParamUsingMappedTypeOverUnionConstraint.ts, 2, 35)) | ||
|
||
declare function test<T extends [number] | [string]>( | ||
>test : Symbol(test, Decl(restParamUsingMappedTypeOverUnionConstraint.ts, 2, 88)) | ||
>T : Symbol(T, Decl(restParamUsingMappedTypeOverUnionConstraint.ts, 4, 22)) | ||
|
||
args: T, | ||
>args : Symbol(args, Decl(restParamUsingMappedTypeOverUnionConstraint.ts, 4, 53)) | ||
>T : Symbol(T, Decl(restParamUsingMappedTypeOverUnionConstraint.ts, 4, 22)) | ||
|
||
fn: (...args: HomomorphicMappedType<T>) => void | ||
>fn : Symbol(fn, Decl(restParamUsingMappedTypeOverUnionConstraint.ts, 5, 10)) | ||
>args : Symbol(args, Decl(restParamUsingMappedTypeOverUnionConstraint.ts, 6, 7)) | ||
>HomomorphicMappedType : Symbol(HomomorphicMappedType, Decl(restParamUsingMappedTypeOverUnionConstraint.ts, 0, 0)) | ||
>T : Symbol(T, Decl(restParamUsingMappedTypeOverUnionConstraint.ts, 4, 22)) | ||
|
||
): void | ||
|
18 changes: 18 additions & 0 deletions
18
tests/baselines/reference/restParamUsingMappedTypeOverUnionConstraint.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
=== tests/cases/compiler/restParamUsingMappedTypeOverUnionConstraint.ts === | ||
// repro 29919#issuecomment-470948453 | ||
|
||
type HomomorphicMappedType<T> = { [P in keyof T]: T[P] extends string ? boolean : null } | ||
>HomomorphicMappedType : HomomorphicMappedType<T> | ||
|
||
declare function test<T extends [number] | [string]>( | ||
>test : <T extends [number] | [string]>(args: T, fn: (...args: HomomorphicMappedType<T>) => void) => void | ||
|
||
args: T, | ||
>args : T | ||
|
||
fn: (...args: HomomorphicMappedType<T>) => void | ||
>fn : (...args: HomomorphicMappedType<T>) => void | ||
>args : HomomorphicMappedType<T> | ||
|
||
): void | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a way, this reverts the recent change from #52651 . That issue is now fixed by avoiding getting the apparent type of mapped types within
getApparentTypeOfContextualType
- you can see the change in the commit hereI think this is a better fix for that issue anyway, I just didn't figure it out earlier. Getting the "resolved" apparent type for mapped types with tuple constraint (and array) constraints is important for relationship checking. The mapped type that resolves~ to a tuple is usually "normalized" here, that allows tuple/array-oriented branches to relate things.