[TypeScript] Add interface, enum, type alias, const literal, new_expression extraction#708
Merged
Conversation
…ression Bring TypeScript AST extraction to parity with Java and C# by adding the declaration types upstream graphify currently skips: - interface_declaration (parity with Java/C# class_types) - enum_declaration + members - type_alias_declaration - module-level const literals (object/array/string/call/new/template/number) via _js_extra_walk extension - new_expression as call type for both _JS_CONFIG and _TS_CONFIG Tested against tests/fixtures/typescript_advanced.ts: 8 expected node types extracted (IUserRepository, UserStatus, UserId, USER_REPOSITORY, DEFAULT_ROLES, USER_CONFIG, UserService, UserModule). Validated on a 3,800-file TypeScript monorepo (NestJS + Next.js): yields ~1,885 interfaces, ~147 enums, ~405 type aliases, ~2,236 const literal nodes, and ~1,935 instantiates edges that were previously invisible.
safishamsi
added a commit
that referenced
this pull request
May 7, 2026
Collaborator
|
Merged via PR #708 (with scalar const type trimming). TypeScript now extracts interface_declaration, enum_declaration, type_alias_declaration, module-level const literals (object/array/as_expression/call_expression/new_expression), and new_expression call edges. Parity with Java/C#. Shipped in v0.7.9. |
hypnwtykvmpr
pushed a commit
to hypnwtykvmpr/vampyre
that referenced
this pull request
May 7, 2026
…t/new_expression extraction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[TypeScript] Add interface, enum, type alias, const literal, new_expression extraction
Summary
Bring TypeScript AST extraction to parity with Java and C# by adding the
declaration types upstream graphify currently skips. Today, TypeScript codebases
yield only
class_declarationandfunction_declarationnodes — nointerface,enum,type alias, module-levelconst, ornew ClassName()edges. This makes the graph blind to the most common TypeScript patterns:
domain model interfaces, enum-driven state machines, dependency injection
configs, and instantiation chains.
Why this matters
Tested against a 21,613-node SharedModel monorepo (NestJS backend +
Next.js 16 frontend, ~3,800 TypeScript files):
explain "AppModule"(NestJS root)contains/configure())explain "User"(entity)users.seed.tsUserentity atuser.entity.ts:54explain "ResultStatus"(enum)path "PrismaUserRepository" "IUserRepository"implements5,702 new nodes (interface 1885, enum 147 + 1038 members, type alias 405,
const literal 2236) and 9,478 new edges (instantiates 1935, references 1231,
NestJS DI 652) extracted from the same corpus.
Java/C# parity reference
Both languages already extract
interface_declarationviaclass_types:This PR brings TypeScript in line.
Changes
1.
_TS_CONFIG— extend class_types and call_types_JS_CONFIGgetsnew_expressiononly (JS does not have interface/enum syntax).2.
_js_extra_walk— extract module-level const/object/array literalsToday,
_js_extra_walkonly handles arrow functions:Extend to also extract the
const NAME = <literal>form, which is howTypeScript codebases declare configs, route maps, enum-like unions, and
factory tokens:
3.
walk_calls— emitinstantiatesedges fromnew_expression4. NestJS
@Module({...})decorator (optional, behind--mode deep)Decorator metadata is a TypeScript-specific pattern. NestJS, Angular, and
similar frameworks express their dependency graph through it. A regex-based
pre-pass (deterministic, no AST recursion needed for the decorator body)
yields edges like:
AppModule --provides--> AuthServiceAppModule --depends_on_module--> SharedModuleAppModule --controls--> UserControllerAppModule --exports--> AuthGuardThis is the entire "wiring" of a NestJS application — currently invisible.
5. (Suggested follow-up, separate PR) MultiGraph upgrade
Today
build_from_jsonreturns anx.Graph(multigraph=False), which meanstwo edges between the same
(src, tgt)pair silently overwrite each other.With the new edge types, ~30% of augment edges collide with upstream
imports/calls/containsedges and are lost.Suggested: switch to
nx.MultiDiGraphwhendirected=Trueis passed (italready exists as a flag), or add a
--multigraphflag. Edge dedup by(src, tgt, relation)instead of(src, tgt).Test fixture
See
tests/fixtures/typescript_advanced.ts:Expected nodes (after this PR):
IUserRepository(interface)UserStatus(enum) +Active,Inactive(members)UserId(type_alias)USER_REPOSITORY(const, kind=call_expression)DEFAULT_ROLES(const, kind=array)UserService(class) — already extractedUserModule(class) — already extractedExpected edges (after this PR):
UserService.create() --instantiates--> UserUserModule --provides--> UserServiceUserModule --provides--> USER_REPOSITORYUserModule --exports--> UserServiceBackward compatibility
tree_sitter_typescriptgrammar._make_idcasing is unchanged — case-collision risk noted in K2 of CLAUDE.mdbut is a pre-existing characteristic of
_make_id, not introduced here.Out of scope (deliberately)
export * from './foo',export { x } from './bar') — needed for accurate const reference edgesbut should be a separate PR with its own pre-pass.
@/*from tsconfig.json) — already handled by_load_tsconfig_aliasesin extract.py for imports; the same helper can bereused for new
referencesedges in a follow-up.Tested against
SharedModel monorepo (~3,800 TypeScript files, NestJS + Next.js 16):
and 9,478 edges when applied through upstream graphify.