Skip to content

Built-in JS/TS methods on untyped values link to project methods with the same name #1987

Description

@bompus

What happens

A JavaScript/TypeScript call to a built-in method on a value whose type isn't resolved links to any project method with that name:

// src/cart.ts
export class Cart {
  add(item: string): void {}
  map(f: (x: string) => string): string[] { return []; }
}
// src/tidy.ts
export function tidy(list: string[], seen: Set<string>) {
  seen.add('x');
  return list.map((x) => x.trim());
}

After codegraph init, the graph has tidy → Cart::map as calls. list.map is Array.prototype.map. On larger code the same shape links this.#items.add(x) on a Set to a project class's add, so the callers, impact and trace of such a method fill with unrelated call sites.

Why

isUnresolvedJsMemberCall only declines member calls with three or more segments (a.b.c). A two-segment list.map whose receiver can't be typed falls through to the method-name strategies, which accept any same-named method.

Expected

When the receiver's type is unknown and the method is a JavaScript built-in (Array, Map/Set, Promise, String, Function, EventTarget/EventEmitter, iterators), the call stays unresolved. A receiver that is typed still resolves normally.

A fix we're running

Our fork declines those calls when the receiver is not this/super and the method name is in a built-in method table: bompus#151. On our gate corpora it only removed edges to project methods named like built-ins. Happy to open a PR against main if you'd like this direction.

Activity

  1. danusha2345 commented on Sep 27, 2026

    @danusha2345
    Contributor

    Two PRs cover this.

    Checked on the fixture from this issue, plus a Store class with #items = new Set<string>() and put(x) { this.#items.add(x) }:

    build calls edges
    main (ba3c21e) tidy → Cart::map, Store::put → Cart::add
    #1941 (913fb3f) Store::put → Cart::add
    #1990 (c0cff45) tidy → Cart::map
    both none
  2. colbymchenry commented on Sep 27, 2026

    @colbymchenry
    Owner

    Thanks for the detailed report, @bompus, and thanks for using CodeGraph! This is fixed on main by #2028, which builds on @danusha2345's #1990 (thank you!): a built-in method call such as list.map(), cache.get() or emitter.emit() on an untyped value no longer links to a project method of the same name, while calls on a constructed, imported, typed or this.#private receiver still resolve. The fix will be in the next release.

  3. added a commit that references this issue on Sep 28, 2026
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions