Skip to content

refactor(deps-resolver): make WantedDependency.alias optional to match aliasless deps #33

Closed
pnpm/pnpm
#16245

Description

@zkochan

Context

The WantedDependency interface declares alias: string (required), but aliasless wanted dependencies exist at runtime — e.g. pnpm add jsr:@x/y, a bare owner/repo#sha, or a GitHub URL, where parseWantedDependency returns no alias. Today these are produced by casting (parseWantedDependencies does ... as WantedDependency[]), so the type doesn't reflect reality and any test/fixture that builds an aliasless wanted dependency is forced into an as unknown as WantedDependency cast.

This was raised by an automated reviewer on pnpm/pnpm#11373; that PR centralized the new test casts into a single helper but did not change the interface, since the proper fix has a broad ripple (see below).

Proposed change

Make alias optional on the wanted-dependency type(s) so the type matches runtime, and remove the casts at the parse seam and in fixtures.

Why it's non-trivial (blast radius)

  • Flipping alias to optional in pnpm11/installing/deps-resolver/src/getNonDevWantedDependencies.ts produces 7 type errors in deps-resolver alone (resolveDependencies.ts, toResolveImporter.ts), where call sites assume alias is a non-null string (map keys, indexing, comparisons).
  • There are two separate WantedDependency interfaces — getNonDevWantedDependencies.ts and getWantedDependencies.ts — both declaring alias: string, consumed across deps-resolver, deps-installer, and command packages. They should likely be unified as part of this.

Scope

  • Decide whether to unify the two WantedDependency interfaces.
  • Make alias optional and fix the call sites that assume it is present (guard, or narrow where an alias is guaranteed).
  • Drop the as unknown as WantedDependency casts (including the aliaslessWantedDependency test helper added in fix: avoid mutating unrelated deps on failed optional updates pnpm#11373) once the type is accurate.

Related to pnpm/pnpm#11373.


Written by an agent (Claude Code, claude-opus-4-8).

Activity

  1. transferred this issue frompnpm/pnpmon Sep 26, 2026
  2. added a commit that references this issue on Oct 5, 2026
    0326cf1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions