Skip to content

The inferred type of X cannot be named without a reference to ark/util when using Brand-Type #1577

Closed

Description

@muuvmuuv

Report a bug

🔎 Search Terms

Using "Branded types" (https://arktype.io/docs/expressions#brand) results in a type error that was fixed in the past here (#1031 and #1049).

The inferred type of 'GraphqlIdentifier' cannot be named without a reference to '.pnpm/@[email protected]/node_modules/@ark/util'. This is likely not portable. A type annotation is necessary.ts(2742)

Possible solutions are installing the EXACT same version and semver range as arktype uses from the locally installed package.

pnpm add -w "@ark/util@$(cat ./node_modules/arktype/package.json | yq -r '.dependencies."@ark/util"')"

🧩 Context

  • ArkType version: ^2.1.29
  • TypeScript version (5.1+): 5.9.3
  • Other context you think may be relevant (JS flavor, OS, etc.): pnpm workspace

🧑‍💻 Repro

Playground Link: https://arktype.io/playground

import { type } from 'arktype'

export const GraphqlIdentifier = type('string.lower#GID')

Activity

  1. added
    bug
    on Jan 6, 2026
  2. changed the title [-]The inferred type of X cannot be named without a reference to ark/util[/-] [+]The inferred type of X cannot be named without a reference to ark/util when using Brand-Type[/+] on Jan 6, 2026
  3. maximvl commented on Apr 10, 2026

    @maximvl

    I'm facing the same issue, adding a comment for visibility.

    I found a workaround:

    type PlayerSlugBranded = string & { __brand: 'PlayerSlug' }
    
    export const PlayerSlugSchema = type('string').pipe((val): PlayerSlugBranded => {
      if (typeof val !== 'string') {
        throw new Error(`Expected a string for PlayerSlug, got ${typeof val}`)
      }
      return val as PlayerSlugBranded
    })
    export type PlayerSlug = typeof PlayerSlugSchema.infer
    
  4. mattidupre commented on Apr 18, 2026

    @mattidupre

    For anyone having the general The inferred type of X cannot be named without a reference to error:

    Fix

    Declare the @ark/* packages ArkType depends on as direct deps of your package, pinned to the exact versions ArkType itself pins. ArkType uses "@ark/util": "0.56.0" (no ^) — your pin has to match, otherwise pnpm will install two copies.

    Single-package repo:

    pnpm add "@ark/util@$(node -p "require('arktype/package.json').dependencies['@ark/util']")"
    # and/or
    pnpm add "@ark/schema@$(node -p "require('arktype/package.json').dependencies['@ark/schema']")"

    pnpm workspace with a catalog:

    # pnpm-workspace.yaml
    catalog:
      arktype: ^2.2.0
      # Pinned in lockstep with ArkType runtime deps — bump together.
      '@ark/util': 0.56.0
      '@ark/schema': 0.56.0
    // package.json of any package whose public API leaks arktype-inferred types
    "dependencies": {
      "arktype": "catalog:",
      "@ark/util": "catalog:",
      "@ark/schema": "catalog:"
    }

    After pnpm install, pnpm links node_modules/@ark/util directly into the consuming package, TS sees it as a direct dep, and the emitted .d.ts uses the bare specifier @ark/util — portable across installs.

    What doesn't fix it

    • public-hoist-pattern[]=@ark/* in .npmrc alone. It makes the package resolvable at the workspace root, but TS still realpath-resolves the symlink into .pnpm/ during declaration emit unless @ark/* is a declared direct dep of the emitting package.
    • A type annotation on the specific declaration (: Type<...>) works locally but has to be repeated wherever the inferred type leaks — not scalable.

    Local workaround if you can't change deps

    Brand manually via .pipe, avoiding ArkType #Name brand syntax so the inferred type doesn't reach into @ark/util:

    type GraphqlIdentifierBranded = string & { readonly __brand: 'GID' };
    
    export const GraphqlIdentifier = type('string.lower').pipe(
      (val): GraphqlIdentifierBranded => val as GraphqlIdentifierBranded,
    );

    Root Cause

    ArkType public types re-export symbols from @ark/util and @ark/schema (e.g. the brand-name machinery lives in @ark/util; ArkErrorCode in @ark/schema). When TypeScript emits the .d.ts for something whose inferred type unfolds into one of those symbols, it needs to name the source module. Since @ark/* aren't listed as direct deps of the emitting package, TS falls back to the shortest path it can find through node_modules — which under pnpm is the store path .pnpm/@[email protected]/…. That path pins a specific pnpm-layout and version slug, so TS correctly flags it as non-portable (TS2742 / TS2883).

  5. added 3 commits that reference this issue on Oct 13, 2026
    46acabb
    3694472
    6129568
  6. ssalbdivad commented on Nov 18, 2026

    @ssalbdivad
    Member

    Fixed in 3.0.0-beta.0 (#1728). Try it with npm i arktype@next.

  7. moved this from To do to Done (merged or closed) in arktypeioon Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

  • Status
    Done (merged or closed)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions