I am parsing a file like this using ts-morph
const a = {property1: 20, property2: 30}
I can't seem to figure out how to get an ObjectLiteralExpression mentioned here
https://ts-morph.com/details/object-literal-expressions
const properties = objectLiteralExpression.getProperties();
// or
const property = objectLiteralExpression.getProperty("propertyAssignment");
// or
const spreadAssignment = objectLiteralExpression.getProperty(
p => p.getText() === "...spreadAssignment",
);
// or
const method = objectLiteralExpression.getPropertyOrThrow("method");
This is what I am using so far. I am getting the initializer which returns an expression, but I can't find a way to get the object literal expression
const project = new Project()
project.addSourceFileAtPath(filePath)
const sourceFile = project.getSourceFileOrThrow(filePath)
const dec = sourceFile.getVariableDeclarationOrThrow(
'a'
)
const objectLiteralExpression = dec.getInitializer() as ObjectLiteralExpression //
console.log(objectLiteralExpression.getProperties())//This returns blank