@@ -79,11 +79,13 @@ import {
7979 isPropertyAccessExpression ,
8080 isPropertyDeclaration ,
8181 isReturnStatement ,
82+ isSatisfiesExpression ,
8283 isSourceFile ,
8384 isSourceFileFromLibrary ,
8485 isSourceFileJS ,
8586 isTransientSymbol ,
8687 isTypeLiteralNode ,
88+ isYieldExpression ,
8789 JsxOpeningLikeElement ,
8890 LanguageVariant ,
8991 lastOrUndefined ,
@@ -141,6 +143,7 @@ const errorCodes = [
141143 Diagnostics . Type_0_is_missing_the_following_properties_from_type_1_Colon_2_and_3_more . code ,
142144 Diagnostics . Argument_of_type_0_is_not_assignable_to_parameter_of_type_1 . code ,
143145 Diagnostics . Cannot_find_name_0 . code ,
146+ Diagnostics . Type_0_does_not_satisfy_the_expected_type_1 . code ,
144147] ;
145148
146149enum InfoKind {
@@ -188,9 +191,11 @@ registerCodeFix({
188191 return createCombinedCodeActions ( textChanges . ChangeTracker . with ( context , changes => {
189192 eachDiagnostic ( context , errorCodes , diag => {
190193 const info = getInfo ( diag . file , diag . start , diag . code , checker , context . program ) ;
191- if ( ! info || ! addToSeen ( seen , getNodeId ( info . parentDeclaration ) + "#" + ( info . kind === InfoKind . ObjectLiteral ? info . identifier : info . token . text ) ) ) {
192- return ;
193- }
194+ if ( info === undefined ) return ;
195+
196+ const nodeId = getNodeId ( info . parentDeclaration ) + "#" + ( info . kind === InfoKind . ObjectLiteral ? info . identifier || getNodeId ( info . token ) : info . token . text ) ;
197+ if ( ! addToSeen ( seen , nodeId ) ) return ;
198+
194199 if ( fixId === fixMissingFunctionDeclaration && ( info . kind === InfoKind . Function || info . kind === InfoKind . Signature ) ) {
195200 addFunctionDeclaration ( changes , context , info ) ;
196201 }
@@ -275,7 +280,7 @@ interface FunctionInfo {
275280interface ObjectLiteralInfo {
276281 readonly kind : InfoKind . ObjectLiteral ;
277282 readonly token : Node ;
278- readonly identifier : string ;
283+ readonly identifier : string | undefined ;
279284 readonly properties : Symbol [ ] ;
280285 readonly parentDeclaration : ObjectLiteralExpression ;
281286 readonly indentation ?: number ;
@@ -320,15 +325,16 @@ function getInfo(sourceFile: SourceFile, tokenPos: number, errorCode: number, ch
320325 return { kind : InfoKind . ObjectLiteral , token : param . name , identifier : param . name . text , properties, parentDeclaration : parent } ;
321326 }
322327
323- if ( token . kind === SyntaxKind . OpenBraceToken && isObjectLiteralExpression ( parent ) ) {
324- const targetType = ( checker . getContextualType ( parent ) || checker . getTypeAtLocation ( parent ) ) ?. getNonNullableType ( ) ;
325- const properties = arrayFrom ( checker . getUnmatchedProperties ( checker . getTypeAtLocation ( parent ) , targetType , /*requireOptionalProperties*/ false , /*matchDiscriminantProperties*/ false ) ) ;
326- if ( ! length ( properties ) ) return undefined ;
327-
328- // no identifier needed because the whole parentDeclaration has the error
329- const identifier = "" ;
328+ if ( token . kind === SyntaxKind . OpenBraceToken || isSatisfiesExpression ( parent ) || isReturnStatement ( parent ) ) {
329+ const expression = ( isSatisfiesExpression ( parent ) || isReturnStatement ( parent ) ) && parent . expression ? parent . expression : parent ;
330+ if ( isObjectLiteralExpression ( expression ) ) {
331+ const targetType = isSatisfiesExpression ( parent ) ? checker . getTypeFromTypeNode ( parent . type ) :
332+ checker . getContextualType ( expression ) || checker . getTypeAtLocation ( expression ) ;
333+ const properties = arrayFrom ( checker . getUnmatchedProperties ( checker . getTypeAtLocation ( parent ) , targetType . getNonNullableType ( ) , /*requireOptionalProperties*/ false , /*matchDiscriminantProperties*/ false ) ) ;
334+ if ( ! length ( properties ) ) return undefined ;
330335
331- return { kind : InfoKind . ObjectLiteral , token : parent , identifier, properties, parentDeclaration : parent } ;
336+ return { kind : InfoKind . ObjectLiteral , token : parent , identifier : undefined , properties, parentDeclaration : expression , indentation : isReturnStatement ( expression . parent ) || isYieldExpression ( expression . parent ) ? 0 : undefined } ;
337+ }
332338 }
333339
334340 if ( ! isMemberName ( token ) ) return undefined ;
0 commit comments