Skip to content

Commit

Permalink
Add another test
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed Mar 6, 2023
1 parent 5688656 commit 20827a5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/baselines/reference/reducibleIndexedAccessTypes.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,24 @@ type GetPayload<P extends Payload, K extends keyof P> = P extends { dataType: K
>K : Symbol(K, Decl(reducibleIndexedAccessTypes.ts, 39, 34))
>P : Symbol(P, Decl(reducibleIndexedAccessTypes.ts, 39, 16))

// Repro from #51161

type AnyOneof = { oneofKind: string; [k: string]: unknown } | { oneofKind: undefined };
>AnyOneof : Symbol(AnyOneof, Decl(reducibleIndexedAccessTypes.ts, 39, 102))
>oneofKind : Symbol(oneofKind, Decl(reducibleIndexedAccessTypes.ts, 43, 17))
>k : Symbol(k, Decl(reducibleIndexedAccessTypes.ts, 43, 38))
>oneofKind : Symbol(oneofKind, Decl(reducibleIndexedAccessTypes.ts, 43, 63))

type AnyOneofKind<T extends AnyOneof> = T extends { oneofKind: keyof T }
>AnyOneofKind : Symbol(AnyOneofKind, Decl(reducibleIndexedAccessTypes.ts, 43, 87))
>T : Symbol(T, Decl(reducibleIndexedAccessTypes.ts, 44, 18))
>AnyOneof : Symbol(AnyOneof, Decl(reducibleIndexedAccessTypes.ts, 39, 102))
>T : Symbol(T, Decl(reducibleIndexedAccessTypes.ts, 44, 18))
>oneofKind : Symbol(oneofKind, Decl(reducibleIndexedAccessTypes.ts, 44, 51))
>T : Symbol(T, Decl(reducibleIndexedAccessTypes.ts, 44, 18))

? T['oneofKind']
>T : Symbol(T, Decl(reducibleIndexedAccessTypes.ts, 44, 18))

: never;

15 changes: 15 additions & 0 deletions tests/baselines/reference/reducibleIndexedAccessTypes.types
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,18 @@ type GetPayload<P extends Payload, K extends keyof P> = P extends { dataType: K
>GetPayload : GetPayload<P, K>
>dataType : K

// Repro from #51161

type AnyOneof = { oneofKind: string; [k: string]: unknown } | { oneofKind: undefined };
>AnyOneof : { [k: string]: unknown; oneofKind: string; } | { oneofKind: undefined; }
>oneofKind : string
>k : string
>oneofKind : undefined

type AnyOneofKind<T extends AnyOneof> = T extends { oneofKind: keyof T }
>AnyOneofKind : AnyOneofKind<T>
>oneofKind : keyof T

? T['oneofKind']
: never;

7 changes: 7 additions & 0 deletions tests/cases/compiler/reducibleIndexedAccessTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,10 @@ const payloads2: MappedPayload2 = {
// Additional repro from 53030

type GetPayload<P extends Payload, K extends keyof P> = P extends { dataType: K } ? P["data"] : never;

// Repro from #51161

type AnyOneof = { oneofKind: string; [k: string]: unknown } | { oneofKind: undefined };
type AnyOneofKind<T extends AnyOneof> = T extends { oneofKind: keyof T }
? T['oneofKind']
: never;

0 comments on commit 20827a5

Please sign in to comment.