Skip to content

TypeScript/JS: method calls on a typed receiver that is a local new binding or a closure-captured parameter are not emitted as calls edges (v0.9.5) #1630

Closed

Description

@DanielC000

Summary

On TypeScript/JavaScript, a member call x.method() does not produce a calls edge to the receiver type's method when x's type comes from (A) a local const x = new Foo() binding, or (B) a closure over a typed parameter (function f(x: Foo) { return () => x.method() }) — even though the receiver's type is statically known. No caller edge is built in either case, so graphify affected <method> reports "No affected nodes found" for a method that is, in fact, called, and it silently under-reports for refactor-impact ("what breaks if I change this method?").

This is the TypeScript/JS analog of #1609 (C#: typed field/param/local receiver calls not emitted). The TS this.field.method() variant was already fixed in #1316 (closed) / v0.9.3's constructor-injected-dependency resolution — but that fix does not extend to a local new binding or a closure-captured parameter, which this issue covers. (The existing TS/JS _resolve_*_member_calls path handles this./unqualified/static-import calls, same gap #1609 describes for C#.)

Related issues

Minimal worked example (3 files)

src/svc.ts

export class Svc {
  doThing(): number { return 1; }
}

src/direct.ts — Pattern A: local variable from new

import { Svc } from "./svc";
const s = new Svc();
export function usesDirect(): number {
  return s.doThing();   // expected: usesDirect --calls--> Svc.doThing
}

src/closure.ts — Pattern B: closure over a typed parameter

import { Svc } from "./svc";
export function register(svc: Svc): () => number {
  return () => svc.doThing();   // expected: register (or its closure) --calls--> Svc.doThing
}

Actual (graphify 0.9.5)

$ graphify affected "doThing" ...
Affected nodes for .doThing()
Depth: 2
No affected nodes found.

$ graphify explain "doThing" ...
Node: .doThing()   Degree: 1
Connections (1):
  <-- Svc [method] [EXTRACTED]

Only the container Svc --method--> doThing edge exists; neither usesDirect nor register is linked.

Expected

affected doThing should list usesDirect and register (or the closure); explain doThing should show incoming [calls] edges from both. Both receivers have a statically-known type (new Svc() and the annotated svc: Svc), so the method target is resolvable without whole-program inference.

Why it matters

For refactor-impact ("who calls / what breaks if I change X"), a silent under-report is worse than no answer — the short result looks complete. Real codebases hit both shapes constantly: dependency objects constructed once and reused, and handlers/callbacks that close over an injected service parameter.

Activity

  1. safishamsi commented on Jul 3, 2026

    @safishamsi
    Member

    Fixed on v8 (4744dfe) — both patterns now resolve.

    • Pattern A (const s = new Svc(); s.doThing()): the per-file type table now learns local new bindings, so the existing receiver-typed resolver binds s -> Svc.
    • Pattern B (closure over a typed param, (svc: Svc) => () => svc.doThing()): two parts — the type table now learns bare-typed parameters, and walk_calls descends into an inline/returned closure (attributing its calls to the enclosing function) instead of stopping at the arrow boundary, so the closure's svc.doThing() is captured and resolved.

    Kept the single-definition guard, so under ambiguity (two doThing across classes) new Svc() binds to Svc.doThing, never Cache.doThing; an untyped param (x) or a non-bare type (Svc[], unions, generics) produces no edge. Verified on the real graphify extract shape (absolute paths + graphify-out cache). 5 tests, full suite green (2871). Ships next release — thanks for the clean two-pattern repro.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions