diff --git a/packages/ts-morph/src/compiler/ast/expression/object/ShorthandPropertyAssignment.ts b/packages/ts-morph/src/compiler/ast/expression/object/ShorthandPropertyAssignment.ts index 6f691692b..c30a5f683 100644 --- a/packages/ts-morph/src/compiler/ast/expression/object/ShorthandPropertyAssignment.ts +++ b/packages/ts-morph/src/compiler/ast/expression/object/ShorthandPropertyAssignment.ts @@ -122,4 +122,19 @@ export class ShorthandPropertyAssignment extends ShorthandPropertyAssignmentBase return structure; } + + /** + * Gets the shorthand assignment value symbol of this node if it exists. Convenience API + * for TypeChecker#getShorthandAssignmentValueSymbol(node) + */ + getValueSymbol() { + return this._context.typeChecker.getShorthandAssignmentValueSymbol(this); + } + + /** + * Gets the value symbol or throws if it doesn't exist. + */ + getValueSymbolOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getValueSymbol(), message ?? "Expected to find a value symbol.", this); + } } diff --git a/packages/ts-morph/src/compiler/tools/TypeChecker.ts b/packages/ts-morph/src/compiler/tools/TypeChecker.ts index e29856da1..03a6ca587 100644 --- a/packages/ts-morph/src/compiler/tools/TypeChecker.ts +++ b/packages/ts-morph/src/compiler/tools/TypeChecker.ts @@ -263,4 +263,12 @@ export class TypeChecker { return formatFlags; } + + /** + * Gets the shorthand assignment value symbol of the provided node. + */ + getShorthandAssignmentValueSymbol(node: Node) { + const symbol = this.compilerObject.getShorthandAssignmentValueSymbol(node.compilerNode) + return symbol ? this._context.compilerFactory.getSymbol(symbol) : undefined + } }