mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 12:32:08 -06:00
fix(52992): no add missing properties quick for nested object literal (#53004)
This commit is contained in:
parent
2ab9e7edd9
commit
0e3e14d39e
@ -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 };
|
||||
|
||||
28
tests/cases/fourslash/codeFixAddMissingProperties28.ts
Normal file
28
tests/cases/fourslash/codeFixAddMissingProperties28.ts
Normal 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: ""
|
||||
}
|
||||
}`,
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user