Skip to content

TypeScript: undeclared external imports exact-match unimported local exports #26

Open

Description

@inth3shadows

Summary

A TypeScript named import from an external package can resolve to an unrelated exported project function that is never imported when the dependency is missing from package metadata. The resulting imports and calls edges are marked exact-match with provenance: null.

Verified on unmodified upstream source, not introduced by the fork customization. This issue tracks the demonstrated variant locally before conditional upstream submission on Tuesday, November 10.

Minimal reproduction

No package.json, tsconfig aliases, ambient declarations or dependency installation:

// main.ts
import { useForm } from 'react-hook-form';
export function entry() { return useForm(); }
// decoy.ts — nothing imports this module
export function useForm() { return 42; }

Index a fresh directory containing those files.

Expected: the external binding stays outside the project/unresolved; no edge targets decoy.ts.

Actual:

Source Kind Target Metadata
main.ts:1 imports decoy.ts:useForm exact-match; null provenance
entry, main.ts:2 calls decoy.ts:useForm exact-match; null provenance

Removing decoy.ts removes the false edges. Merely declaring react-hook-form in a minimal package.json dependency entry also removes them without installing the dependency.

Independent upstream verification

Checked 2026-11-08 on Linux/WSL, Node 22.22.2, kernel 0/WASM:

Subject Pinned commit Result
Official upstream v1.6.2 tag 6560052a6f856855d3f71eee838fd66ccfa4285d Same 3 semantic failures, 4 controls pass
Official upstream main f72c9d2efb14454ff4f9fd7b8460abd82f19a287 Same 3 semantic failures, 4 controls pass
Deployed em.40 fork 5e0664891af0e87e6fd18bbfa16cab39237570f5 Same 3 semantic failures, 4 controls pass

The two official upstream checkouts were cloned directly from colbymchenry/codegraph, installed using fresh locked dependencies with npm ci --ignore-scripts --no-audit --no-fund, then built with each checkout's official npm run build. No fork source, node_modules, runtime or grammar files were reused. Both upstream source trees remained pristine after build and testing.

All 21 fresh indexes completed successfully. The seven case/edge records match exactly across all three subjects.

Controls and failure condition

  • External import with no decoy: no false edge.
  • External import with matching local export: false import and call.
  • Aliased import with a decoy matching the original export name only: no false edge.
  • Aliased import with a decoy matching the local alias: false import and call.
  • Inner function shadows the imported name: legitimate local call remains correct, but the import falsely targets the decoy.
  • Dependency declared but not installed: no false edge.
  • Genuine relative import beside an identical-name decoy: correctly calls the real module.

A fix must preserve legitimate lexical shadows and real module/alias/workspace/ambient resolution.

Source explanation

In the tested upstream main and em.40 source:

  1. context.isOutOfRepoImport in src/resolution/index.ts:879–883 checks external syntax and absence of an indexed local module, then delegates to isDeclaredOutsidePackage.
  2. isDeclaredOutsidePackage at index.ts:4674–4687 returns false for an ordinary undeclared package without dependency metadata.
  3. isOutOfRepoBinding at name-matcher.ts:25486–25491 therefore does not protect the external binding.
  4. The exact-name path at name-matcher.ts:14345–14375 and 14544–14552 accepts the unrelated exported function.

The inheritance-only guard is insufficient for calls/imports; simply moving it to cover every reference could break lexical shadows. The correction needs import-boundary semantics rather than relying solely on dependency declarations.

Evidence and related work

Related upstream #2101 is closed and covers fuzzy resolution with a declared dependency. This is an exact-match/missing-metadata variant of the same broad family; no claim that the variant is entirely novel. #2962 concerns a different spread-call defect and supplied the selected fixture.

This is pre-existing behavior, not a new em.40 regression. The broader QA run's 51 finding rows are not 51 newly confirmed bugs.

Status and limits

Evidence/report only; no resolver fix or deployment is included. No report has been submitted to the official upstream for this verified variant.

Plan: final verification and duplicate check on Tuesday, November 10; report upstream if everything still checks out. Native-kernel behavior, published npm/platform binaries, other languages and real-project prevalence remain unverified.

Activity

  1. inth3shadows commented on Nov 11, 2026

    @inth3shadows
    OwnerAuthor

    Filed upstream as colbymchenry#3271 (2026-11-11), re-verified on upstream main f72c9d2. No fix PR yet.

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