Skip to content

Stack overflow in type instantiation with recursive function and generic type params #2935

@wadjoh

Description

@wadjoh

Description

A project at my job causes a stack overflow with tsgo, but compiles with tsc.
Tracked it down to a recursive object transformation function that changes the casing of the object's string properties.
It uses the CamelCase type from type-fest.

I have a code example that's as minimal as I could figure out how to make it: https://github.com/wadjoh/tsgo-crash-repro.

EDIT: The crashing seems to have started happening with type-fest version 4.38.0 and starts working again with version 5.0.0.
Change in 4.38.0 that started causing the crashing: sindresorhus/type-fest#1081
Diff of 4.41.0 and 5.0.0 (not sure which of the changes stops the crashing): sindresorhus/type-fest@v4.41.0...v5.0.0

Stack trace

The full stack trace is large so I'll paste the first part of it here and paste a link to a gist with the full stack trace.

runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0x44423d7f0570 stack=[0x44423d7f0000, 0x44425d7f0000]
fatal error: stack overflow

runtime stack:
runtime.throw({0x104c6d915?, 0x1045baed4?})
        runtime/panic.go:1229 +0x38 fp=0x16b8768e0 sp=0x16b8768b0 pc=0x1046015d8
runtime.newstack()
        runtime/stack.go:1178 +0x498 fp=0x16b876a10 sp=0x16b8768e0 pc=0x1045e8648
runtime.morestack()
        runtime/asm_arm64.s:507 +0x70 fp=0x16b876a10 sp=0x16b876a10 pc=0x104607070

Full stack trace: https://gist.github.com/wadjoh/82adc287ab15357812c8e2da247163c3

Steps to reproduce

  1. Clone https://github.com/wadjoh/tsgo-crash-repro
  2. Run pnpm i
  3. Run pnpm check:tsgo
  4. Observe stack overflow panic

You can also run pnpm check:tsc and see that it successfully compiles.

Example code that causes the crash

import { CamelCase } from "type-fest";

const transform = <TResult>(iteratee: any): TResult => undefined as any;
const camelize = <T extends object>(): CamelCase<T> => transform(camelize);

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions