ts-morph
28.0.0 · 12 Apr 2026MIT46.3M / weekRepositoryHomepagenpmAtom feed
3.1.3 is the newest release of 3.x.
In short
5 breaking16 new2 faster7 fixed5 internal
- Breaking
renameNodeandrenameLocationsare removed from the language service. To be consistent, the language service should not have methods that manipulate nodes. - Breaking
SourceFile#getTypeReferenceDirectives()and#getReferencedFiles()now return the objects similar to what the compiler api returns. - Breaking
Node#forEachChildis now aligned with the compiler API (same withforEachDescendant). These methods now stop when a value is returned in a callback and they will return the returned value. - Breaking
The
ObjectLiteralElementMemberStructuresalias is now calledObjectLiteralExpressionPropertyStructures. This is a more correct name as an object literal expression has "properties" rather than "members" in the compiler api. - Breaking
Renamed
StructureTypeGuardsmethods to remove wordNodeandDeclarationin certain cases.
Release note
The section about ts-morph of a note shared by several packages.
Bug Fixes
Incorrect type resolution behaviour when providing a tsconfig.json file path and having a different current working directory.
Comment nodes are no longer accidentally returned in some scenarios.
ClassLike and TypeElementMembered nodes would not get the correct "add" index when a comment member node was present.
Comment node parser now correctly returns comments on next line after tailing comma in object literal expressions.
Fix issues with
Node#getText({ trimLeadingIndentation: true })indenting more than it should.ObjectLiteralExpression insert should insert around comment nodes. (c3b9f28), closes #605
Support nodes that may not have a source file (ex.
globalThisnode returned from a symbol)
Features
Add
Symbol#getExportSymbolandTypeChecker#getExportSymbolOfSymbol.Add methods
Node#getLocals,#getLocalByName,#getLocalByNameOrThrowAdd ability to insert comments on enum declarations.
Add insertMember-like methods to
ClassLikeDeclarationBase.Add insertMember-like methods to
TypeElementMemberedNode.ObjectLiteralExpression#insertProperties and similar methods.
Add
writer.withHangingIndent(() => {}). Also better hanging indent printing (a544e55), closes #616Add
Writersalias forWriterFunctions.Writers.returnStatement should do hanging indent in certain cases.
RenameLocation - Support
prefixTextandsuffixTextwhen renaming.RenameLocation- AddgetPrefixText()andgetSuffixText()Add
Node#getSymbolsInScope(meaning)andTypeChecker#getSymbolsInScope(node, meaning).Add TypeGuards.isCommentNode.
Add WriterFunctions.assertion.
Smart comma insertion when printing comma separated values with comments.
Upgrade to code-block-writer 9.4.0.
Performance Improvements
Remove some internal regular expressions.
Improve performance of
SourceFile#indent()anddeindent().
Breaking changes
- Breaking
renameNodeandrenameLocationsare removed from the language service. To be consistent, the language service should not have methods that manipulate nodes. - Breaking
SourceFile#getTypeReferenceDirectives()and#getReferencedFiles()now return the objects similar to what the compiler api returns. - Breaking
Node#forEachChildis now aligned with the compiler API (same withforEachDescendant). These methods now stop when a value is returned in a callback and they will return the returned value. - Breaking
The
ObjectLiteralElementMemberStructuresalias is now calledObjectLiteralExpressionPropertyStructures. This is a more correct name as an object literal expression has "properties" rather than "members" in the compiler api. - Breaking
Renamed
StructureTypeGuardsmethods to remove wordNodeandDeclarationin certain cases.
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.