Skip to content

Commit fa43c1c

Browse files
committed
Infer unknown at value positions of objects inferred from keyof T
1 parent 4b15830 commit fa43c1c

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24526,7 +24526,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2452624526
isTypeParameterAtTopLevel(getReturnTypeOfSignature(signature), typeParameter);
2452724527
}
2452824528

24529-
/** Create an object with properties named in the string literal type. Every property has type `any` */
24529+
/** Create an object with properties named in the string literal type. Every property has type `unknown` */
2453024530
function createEmptyObjectTypeFromStringLiteral(type: Type) {
2453124531
const members = createSymbolTable();
2453224532
forEachType(type, t => {
@@ -24535,7 +24535,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2453524535
}
2453624536
const name = escapeLeadingUnderscores((t as StringLiteralType).value);
2453724537
const literalProp = createSymbol(SymbolFlags.Property, name);
24538-
literalProp.links.type = anyType;
24538+
literalProp.links.type = unknownType;
2453924539
if (t.symbol) {
2454024540
literalProp.declarations = t.symbol.declarations;
2454124541
literalProp.valueDeclaration = t.symbol.valueDeclaration;

tests/baselines/reference/inferObjectTypeFromStringLiteralToKeyof.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ declare var two: "a" | "d";
1414
>two : "a" | "d"
1515

1616
const x = inference1(two);
17-
>x : { a: any; d: any; }
18-
>inference1(two) : { a: any; d: any; }
17+
>x : { a: unknown; d: unknown; }
18+
>inference1(two) : { a: unknown; d: unknown; }
1919
>inference1 : <T>(name: keyof T) => T
2020
>two : "a" | "d"
2121

tests/baselines/reference/keyofInferenceIntersectsResults.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ const a = foo<X>('a', 'b'); // compiles cleanly
2727
>'b' : "b"
2828

2929
const b = foo('a', 'b'); // also clean
30-
>b : { a: any; } & { b: any; }
31-
>foo('a', 'b') : { a: any; } & { b: any; }
30+
>b : { a: unknown; } & { b: unknown; }
31+
>foo('a', 'b') : { a: unknown; } & { b: unknown; }
3232
>foo : <T = X>(x: keyof T, y: keyof T) => T
3333
>'a' : "a"
3434
>'b' : "b"
3535

3636
const c = bar('a', 'b'); // still clean
37-
>c : { a: any; } & { b: any; }
38-
>bar('a', 'b') : { a: any; } & { b: any; }
37+
>c : { a: unknown; } & { b: unknown; }
38+
>bar('a', 'b') : { a: unknown; } & { b: unknown; }
3939
>bar : <T>(x: keyof T, y: keyof T) => T
4040
>'a' : "a"
4141
>'b' : "b"

0 commit comments

Comments
 (0)