@@ -187,7 +187,7 @@ registerCodeFix({
187
187
return createCombinedCodeActions ( textChanges . ChangeTracker . with ( context , changes => {
188
188
eachDiagnostic ( context , errorCodes , diag => {
189
189
const info = getInfo ( diag . file , diag . start , diag . code , checker , context . program ) ;
190
- if ( ! info || ! addToSeen ( seen , getNodeId ( info . parentDeclaration ) + "#" + info . token . text ) ) {
190
+ if ( ! info || ! addToSeen ( seen , getNodeId ( info . parentDeclaration ) + "#" + ( info . kind === InfoKind . ObjectLiteral ? info . identifier : info . token . text ) ) ) {
191
191
return ;
192
192
}
193
193
if ( fixId === fixMissingFunctionDeclaration && ( info . kind === InfoKind . Function || info . kind === InfoKind . Signature ) ) {
@@ -273,7 +273,8 @@ interface FunctionInfo {
273
273
274
274
interface ObjectLiteralInfo {
275
275
readonly kind : InfoKind . ObjectLiteral ;
276
- readonly token : Identifier ;
276
+ readonly token : Node ;
277
+ readonly identifier : string ;
277
278
readonly properties : Symbol [ ] ;
278
279
readonly parentDeclaration : ObjectLiteralExpression ;
279
280
readonly indentation ?: number ;
@@ -315,7 +316,18 @@ function getInfo(sourceFile: SourceFile, tokenPos: number, errorCode: number, ch
315
316
316
317
const properties = arrayFrom ( checker . getUnmatchedProperties ( checker . getTypeAtLocation ( parent ) , checker . getParameterType ( signature , argIndex ) , /*requireOptionalProperties*/ false , /*matchDiscriminantProperties*/ false ) ) ;
317
318
if ( ! length ( properties ) ) return undefined ;
318
- return { kind : InfoKind . ObjectLiteral , token : param . name , properties, parentDeclaration : parent } ;
319
+ return { kind : InfoKind . ObjectLiteral , token : param . name , identifier : param . name . text , properties, parentDeclaration : parent } ;
320
+ }
321
+
322
+ if ( token . kind === SyntaxKind . OpenBraceToken && isObjectLiteralExpression ( parent ) ) {
323
+ const targetType = checker . getContextualType ( parent ) || checker . getTypeAtLocation ( parent ) ;
324
+ const properties = arrayFrom ( checker . getUnmatchedProperties ( checker . getTypeAtLocation ( parent ) , targetType , /*requireOptionalProperties*/ false , /*matchDiscriminantProperties*/ false ) ) ;
325
+ if ( ! length ( properties ) ) return undefined ;
326
+
327
+ // no identifier needed because the whole parentDeclaration has the error
328
+ const identifier = "" ;
329
+
330
+ return { kind : InfoKind . ObjectLiteral , token : parent , identifier, properties, parentDeclaration : parent } ;
319
331
}
320
332
321
333
if ( ! isMemberName ( token ) ) return undefined ;
@@ -325,7 +337,7 @@ function getInfo(sourceFile: SourceFile, tokenPos: number, errorCode: number, ch
325
337
const properties = arrayFrom ( checker . getUnmatchedProperties ( checker . getTypeAtLocation ( parent . initializer ) , targetType , /*requireOptionalProperties*/ false , /*matchDiscriminantProperties*/ false ) ) ;
326
338
if ( ! length ( properties ) ) return undefined ;
327
339
328
- return { kind : InfoKind . ObjectLiteral , token, properties, parentDeclaration : parent . initializer } ;
340
+ return { kind : InfoKind . ObjectLiteral , token, identifier : token . text , properties, parentDeclaration : parent . initializer } ;
329
341
}
330
342
331
343
if ( isIdentifier ( token ) && isJsxOpeningLikeElement ( token . parent ) ) {
0 commit comments