mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
feat(52097): "Add missing properties" quick fix for calculated string values ... (#52135)
This commit is contained in:
@@ -694,7 +694,7 @@ function tryGetValueFromType(context: CodeFixContextBase, checker: TypeChecker,
|
||||
}
|
||||
if (isObjectLiteralType(type)) {
|
||||
const props = map(checker.getPropertiesOfType(type), prop => {
|
||||
const initializer = prop.valueDeclaration ? tryGetValueFromType(context, checker, importAdder, quotePreference, checker.getTypeAtLocation(prop.valueDeclaration), enclosingDeclaration) : createUndefined();
|
||||
const initializer = tryGetValueFromType(context, checker, importAdder, quotePreference, checker.getTypeOfSymbol(prop), enclosingDeclaration);
|
||||
return factory.createPropertyAssignment(prop.name, initializer);
|
||||
});
|
||||
return factory.createObjectLiteralExpression(props, /*multiLine*/ true);
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////interface Foo {
|
||||
//// a?: boolean;
|
||||
//// b: boolean;
|
||||
////}
|
||||
////type A = { [K in keyof Foo]-?: { name: K, value: `Foo ${Uppercase<K>}` }}
|
||||
////[|const a: A = {};|]
|
||||
|
||||
verify.codeFix({
|
||||
index: 0,
|
||||
description: ts.Diagnostics.Add_missing_properties.message,
|
||||
newRangeContent:
|
||||
`const a: A = {
|
||||
a: {
|
||||
name: "a",
|
||||
value: "Foo A"
|
||||
},
|
||||
b: {
|
||||
name: "b",
|
||||
value: "Foo B"
|
||||
}
|
||||
};`,
|
||||
});
|
||||
Reference in New Issue
Block a user