Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19611,7 +19611,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
isGenericTupleType(objectType) && !indexTypeLessThan(indexType, getTotalFixedElementCount(objectType.target)) :
isGenericObjectType(objectType) && !(isTupleType(objectType) && indexTypeLessThan(indexType, getTotalFixedElementCount(objectType.target))) || isGenericReducibleType(objectType))
) {
if (objectType.flags & TypeFlags.AnyOrUnknown) {
if (objectType.flags & (TypeFlags.AnyOrUnknown | TypeFlags.Never)) {
return objectType;
}
// Defer the operation by creating an indexed access type.
Expand Down
4 changes: 4 additions & 0 deletions tests/baselines/reference/keyofAndIndexedAccess.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -694,4 +694,8 @@ keyofAndIndexedAccess.ts(318,5): error TS2322: Type 'T[K]' is not assignable to
const s: string = t[k];
t.cool;
};

type IndexedNever<T> = never[keyof T];
type IndexedAny<T> = any[keyof T];
type IndexedUnknown<T> = unknown[keyof T];

7 changes: 7 additions & 0 deletions tests/baselines/reference/keyofAndIndexedAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,10 @@ const cf2 = <T extends { [P in K | "cool"]: string; }, K extends keyof T>(t: T,
const s: string = t[k];
t.cool;
};

type IndexedNever<T> = never[keyof T];
type IndexedAny<T> = any[keyof T];
type IndexedUnknown<T> = unknown[keyof T];


//// [keyofAndIndexedAccess.js]
Expand Down Expand Up @@ -1435,3 +1439,6 @@ declare const cf1: <T extends { [P in K]: string; } & {
cool: string;
}, K extends keyof T>(t: T, k: K) => void;
declare const cf2: <T extends { [P in K | "cool"]: string; }, K extends keyof T>(t: T, k: K) => void;
type IndexedNever<T> = never[keyof T];
type IndexedAny<T> = any[keyof T];
type IndexedUnknown<T> = unknown[keyof T];
15 changes: 15 additions & 0 deletions tests/baselines/reference/keyofAndIndexedAccess.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -2345,3 +2345,18 @@ const cf2 = <T extends { [P in K | "cool"]: string; }, K extends keyof T>(t: T,

};

type IndexedNever<T> = never[keyof T];
>IndexedNever : Symbol(IndexedNever, Decl(keyofAndIndexedAccess.ts, 656, 2))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 658, 18))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 658, 18))

type IndexedAny<T> = any[keyof T];
>IndexedAny : Symbol(IndexedAny, Decl(keyofAndIndexedAccess.ts, 658, 38))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 659, 16))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 659, 16))

type IndexedUnknown<T> = unknown[keyof T];
>IndexedUnknown : Symbol(IndexedUnknown, Decl(keyofAndIndexedAccess.ts, 659, 34))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 660, 20))
>T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 660, 20))

12 changes: 12 additions & 0 deletions tests/baselines/reference/keyofAndIndexedAccess.types
Original file line number Diff line number Diff line change
Expand Up @@ -3450,3 +3450,15 @@ const cf2 = <T extends { [P in K | "cool"]: string; }, K extends keyof T>(t: T,

};

type IndexedNever<T> = never[keyof T];
>IndexedNever : never
> : ^^^^^

type IndexedAny<T> = any[keyof T];
>IndexedAny : any
> : ^^^

type IndexedUnknown<T> = unknown[keyof T];
>IndexedUnknown : unknown
> : ^^^^^^^

4 changes: 4 additions & 0 deletions tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -658,3 +658,7 @@ const cf2 = <T extends { [P in K | "cool"]: string; }, K extends keyof T>(t: T,
const s: string = t[k];
t.cool;
};

type IndexedNever<T> = never[keyof T];
type IndexedAny<T> = any[keyof T];
type IndexedUnknown<T> = unknown[keyof T];