fix(52992): no add missing properties quick for nested object literal (#53004)

This commit is contained in:
Oleksandr T 2023-03-09 20:00:55 +02:00 committed by GitHub
parent 2ab9e7edd9
commit 0e3e14d39e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -317,7 +317,8 @@ function getInfo(sourceFile: SourceFile, tokenPos: number, errorCode: number, ch
if (!isMemberName(token)) return undefined;
if (isIdentifier(token) && hasInitializer(parent) && parent.initializer && isObjectLiteralExpression(parent.initializer)) {
const properties = arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent.initializer), checker.getTypeAtLocation(token), /* requireOptionalProperties */ false, /* matchDiscriminantProperties */ false));
const targetType = checker.getContextualType(token) || checker.getTypeAtLocation(token);
const properties = arrayFrom(checker.getUnmatchedProperties(checker.getTypeAtLocation(parent.initializer), targetType, /* requireOptionalProperties */ false, /* matchDiscriminantProperties */ false));
if (!length(properties)) return undefined;
return { kind: InfoKind.ObjectLiteral, token, properties, parentDeclaration: parent.initializer };

View File

@ -0,0 +1,28 @@
/// <reference path="fourslash.ts" />
////interface Foo {
//// a: number;
//// b: string;
////}
////
////interface Bar {
//// value: Foo;
////}
////
////[|const bar: Bar = {
//// value: {
//// a: 10
//// }
////}|]
verify.codeFix({
index: 0,
description: ts.Diagnostics.Add_missing_properties.message,
newRangeContent:
`const bar: Bar = {
value: {
a: 10,
b: ""
}
}`,
});