@@ -79,11 +79,13 @@ import {
79
79
isPropertyAccessExpression ,
80
80
isPropertyDeclaration ,
81
81
isReturnStatement ,
82
+ isSatisfiesExpression ,
82
83
isSourceFile ,
83
84
isSourceFileFromLibrary ,
84
85
isSourceFileJS ,
85
86
isTransientSymbol ,
86
87
isTypeLiteralNode ,
88
+ isYieldExpression ,
87
89
JsxOpeningLikeElement ,
88
90
LanguageVariant ,
89
91
lastOrUndefined ,
@@ -141,6 +143,7 @@ const errorCodes = [
141
143
Diagnostics . Type_0_is_missing_the_following_properties_from_type_1_Colon_2_and_3_more . code ,
142
144
Diagnostics . Argument_of_type_0_is_not_assignable_to_parameter_of_type_1 . code ,
143
145
Diagnostics . Cannot_find_name_0 . code ,
146
+ Diagnostics . Type_0_does_not_satisfy_the_expected_type_1 . code ,
144
147
] ;
145
148
146
149
enum InfoKind {
@@ -188,9 +191,11 @@ registerCodeFix({
188
191
return createCombinedCodeActions ( textChanges . ChangeTracker . with ( context , changes => {
189
192
eachDiagnostic ( context , errorCodes , diag => {
190
193
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
+
194
199
if ( fixId === fixMissingFunctionDeclaration && ( info . kind === InfoKind . Function || info . kind === InfoKind . Signature ) ) {
195
200
addFunctionDeclaration ( changes , context , info ) ;
196
201
}
@@ -275,7 +280,7 @@ interface FunctionInfo {
275
280
interface ObjectLiteralInfo {
276
281
readonly kind : InfoKind . ObjectLiteral ;
277
282
readonly token : Node ;
278
- readonly identifier : string ;
283
+ readonly identifier : string | undefined ;
279
284
readonly properties : Symbol [ ] ;
280
285
readonly parentDeclaration : ObjectLiteralExpression ;
281
286
readonly indentation ?: number ;
@@ -320,15 +325,16 @@ function getInfo(sourceFile: SourceFile, tokenPos: number, errorCode: number, ch
320
325
return { kind : InfoKind . ObjectLiteral , token : param . name , identifier : param . name . text , properties, parentDeclaration : parent } ;
321
326
}
322
327
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 ;
330
335
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
+ }
332
338
}
333
339
334
340
if ( ! isMemberName ( token ) ) return undefined ;
0 commit comments