Skip to content

Commit 0e3e14d

Browse files
authored
fix(52992): no add missing properties quick for nested object literal (microsoft#53004)
1 parent 2ab9e7e commit 0e3e14d

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/services/codefixes/fixAddMissingMember.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ function getInfo(sourceFile: SourceFile, tokenPos: number, errorCode: number, ch
317317
if (!isMemberName(token)) return undefined;
318318

319319
if (isIdentifier(token) && hasInitializer(parent) && parent.initializer && isObjectLiteralExpression(parent.initializer)) {
320-
const properties = arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent.initializer), checker.getTypeAtLocation(token), /* requireOptionalProperties */ false, /* matchDiscriminantProperties */ false));
320+
const targetType = checker.getContextualType(token) || checker.getTypeAtLocation(token);
321+
const properties = arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent.initializer), targetType, /* requireOptionalProperties */ false, /* matchDiscriminantProperties */ false));
321322
if (!length(properties)) return undefined;
322323

323324
return { kind: InfoKind.ObjectLiteral, token, properties, parentDeclaration: parent.initializer };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
////interface Foo {
4+
//// a: number;
5+
//// b: string;
6+
////}
7+
////
8+
////interface Bar {
9+
//// value: Foo;
10+
////}
11+
////
12+
////[|const bar: Bar = {
13+
//// value: {
14+
//// a: 10
15+
//// }
16+
////}|]
17+
18+
verify.codeFix({
19+
index: 0,
20+
description: ts.Diagnostics.Add_missing_properties.message,
21+
newRangeContent:
22+
`const bar: Bar = {
23+
value: {
24+
a: 10,
25+
b: ""
26+
}
27+
}`,
28+
});

0 commit comments

Comments
 (0)