@@ -187,7 +187,7 @@ registerCodeFix({
187187 return createCombinedCodeActions ( textChanges . ChangeTracker . with ( context , changes => {
188188 eachDiagnostic ( context , errorCodes , diag => {
189189 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 ) ) ) {
191191 return ;
192192 }
193193 if ( fixId === fixMissingFunctionDeclaration && ( info . kind === InfoKind . Function || info . kind === InfoKind . Signature ) ) {
@@ -273,7 +273,8 @@ interface FunctionInfo {
273273
274274interface ObjectLiteralInfo {
275275 readonly kind : InfoKind . ObjectLiteral ;
276- readonly token : Identifier ;
276+ readonly token : Node ;
277+ readonly identifier : string ;
277278 readonly properties : Symbol [ ] ;
278279 readonly parentDeclaration : ObjectLiteralExpression ;
279280 readonly indentation ?: number ;
@@ -315,7 +316,18 @@ function getInfo(sourceFile: SourceFile, tokenPos: number, errorCode: number, ch
315316
316317 const properties = arrayFrom ( checker . getUnmatchedProperties ( checker . getTypeAtLocation ( parent ) , checker . getParameterType ( signature , argIndex ) , /*requireOptionalProperties*/ false , /*matchDiscriminantProperties*/ false ) ) ;
317318 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 } ;
319331 }
320332
321333 if ( ! isMemberName ( token ) ) return undefined ;
@@ -325,7 +337,7 @@ function getInfo(sourceFile: SourceFile, tokenPos: number, errorCode: number, ch
325337 const properties = arrayFrom ( checker . getUnmatchedProperties ( checker . getTypeAtLocation ( parent . initializer ) , targetType , /*requireOptionalProperties*/ false , /*matchDiscriminantProperties*/ false ) ) ;
326338 if ( ! length ( properties ) ) return undefined ;
327339
328- return { kind : InfoKind . ObjectLiteral , token, properties, parentDeclaration : parent . initializer } ;
340+ return { kind : InfoKind . ObjectLiteral , token, identifier : token . text , properties, parentDeclaration : parent . initializer } ;
329341 }
330342
331343 if ( isIdentifier ( token ) && isJsxOpeningLikeElement ( token . parent ) ) {
0 commit comments