Skip to content

fix(typescript): resolve calls through optional typed properties - #5655

Open
rvitaliy wants to merge 1 commit into
Graphify-Labs:v8from
rvitaliy:feature/ts-optional-property-calls
Open

rvitaliy wants to merge 1 commit into
Graphify-Labs:v8from
rvitaliy:feature/ts-optional-property-calls

Conversation

@rvitaliy

@rvitaliy rvitaliy commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #5654. A route factory can capture a parameter typed as Pick<Dependencies, 'service' | 'config'> and call either deps.service?.get() or deps.config?.store.get(). Graphify already knows how to follow the declared dependency types across files. The TypeScript extractor dropped that evidence when it encountered optional member access, so neither method showed the route as a caller.

Record each ?. on the receiver immediately to its left while reading the property path. The existing resolver can then infer the exact declared method using the same evidence it uses for a non-null assertion. This represents a possible call when the receiver exists. A guard for one hop cannot satisfy a different optional hop. For example, deps.service.get?.() guards the method invocation and leaves an optional service unguarded.

Verification & invariants

  • Reproduced on v0.9.124 (d249de367). All three new regression cases fail on that commit.
  • The regression models two async route handlers closed over imported, optional dependencies. Their interfaces both declare get. It asserts the exact caller, declaration file, owner, member, call-site line and INFERRED confidence for full extraction and a caller-only incremental extraction.
  • Tests exercise two guarded hops and a guard combined with a non-null assertion. Misplaced guards, interrupted chains, opaque unions and unknown receivers stay unlinked. Computed keys and optional access on the root parameter remain outside this typed property resolver.
  • Bumped the AST cache schema to 61 and updated the architecture notes. For an existing raw graph with unchanged sources, run graphify extract . --code-only --no-cluster --force once. Verified that a subsequent caller-only edit preserves both targets and updates the source lines.
  • Read the contribution guide and disclosed AI assistance in the commit. The tests use synthetic TypeScript.

How was this tested?

  • Compared two cold extractions of the same 838 production TypeScript files in a downstream project. The base produced no call edge at five known sites. With the patch, each site produces exactly one AST-derived INFERRED edge to its declared method, including two identically named methods on different stores.
  • python -m pytest -q tests/test_ts_typed_property_receivers.py tests/test_ts_receiver_member_calls.py passed on Python 3.11 and 3.13 (77 tests each). The typed-property regression file also passed on Python 3.14.
  • uv run --locked --all-extras ruff check ., git diff --check and uv run --locked --all-extras graphify update . passed. uv run --locked --all-extras pyright --outputjson reported the same 767 diagnostics on base and head, compared by file, severity and message.
  • Full local suite on CPython 3.14.6: 12,628 passed, 135 skipped, 2 expected failures. Ran the non-serial set with pytest tests -q --tb=short -n 6 --dist worksteal -m 'not serial', excluding the worker-size and three language-override modules from that invocation and running their non-serial cases in one process. Ran pytest tests -q --tb=short -m serial for the serial set.

Retain the optional access at the exact receiver hop so route callbacks can resolve a unique method through imported dependencies. Check both direct and nested access and reject paths with an unguarded optional hop. Bump the AST cache schema to re-extract older caller facts.

Refs Graphify-Labs#5654.

Co-Authored-By: Codex <[email protected]>
@rvitaliy
rvitaliy requested a review from safishamsi as a code owner November 30, 2026 20:12
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @rvitaliy. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 30, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify review View in Graphify

Looks safe to merge · Merge confidence 5/5

No issues reported · High impact

The TypeScript extractor now follows typed property paths through optional-chain and non-null guards.

What this review covered
  • We didn't review 1 file that isn't source code, such as docs, config, images, or generated or third-party code.
  • Part of a file with a line too long to show was not read.
  • A changed file's diff was too long to show in full, so the review may not have seen every changed line in it; the in-depth pass still reviewed every changed file.
  • 4 of 4 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 6555 functions depend on this change
  • 665 of 665 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed a4ac850

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TypeScript calls through optional typed dependencies are missing from the graph

1 participant