Skip to content

tsgo hangs with class/namespace merge + recursive types + declaration:true #2403

@jasonkuhrt

Description

@jasonkuhrt

Summary

tsgo hangs indefinitely on code that tsc handles fine.

Reproduction

https://github.com/jasonkuhrt/repro-tsgo-hang

pnpm install
pnpm demo:works  # tsc completes
pnpm demo:hangs  # tsgo hangs

Workarounds

  • Exporting the internal Thing_ type fixes hang
  • Removing declaration:true from tsconfig fixes hang
  • Removing namespace wrapper fixes hang

Minimal Code

tsconfig.json

{
  "compilerOptions": {
    "noEmit": true,
    "declaration": true
  },
  "include": ["repro.ts"]
}

repro.ts

type U<$A, $B, $C> =
  $B extends 0    ? any :
  $A extends any  ? Omit<$A, 0> & $C :
                    any

export class A {
  static fromString = <$input>(
    input: A.Thing<$input, A.NameEmpty>
  ) => null as any
}

export namespace A {
  export type Name = { b: any[]; a: any }
  export type NameEmpty = { b: []; a: null }

  type Add<$A extends Name, $B> =
    $A['a'] extends any
      ? U<$A, '', $B>
      : U<$A, '', $B>

  export type Thing<$A, $B extends Name> = Thing_<$A, $B>

  type Thing_<$A, $B extends Name> =
    $A extends `` ? $B :
    $A extends `${infer v} ${infer tail}` ? Thing_<tail, Add<$B, v>> :
    $A extends `${infer v}` ? Add<$B, v> :
    'unknown'
}

Environment

  • tsgo: 7.0.0-dev.20251216.1 (@typescript/native-preview)
  • tsc: 5.7.2

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