Skip to content

panic: runtime error: slice bounds out of range [:52400] with length 524 when processing Knex module augmentations #1408

@vpontis

Description

@vpontis

tsgo panics when processing Knex module augmentations with complex generic constraints.

Reproduction

Minimal reproduction: https://github.com/vpontis/tsgo-panic

git clone https://github.com/vpontis/tsgo-panic
cd tsgo-panic
bun install
bun tsgo  # panics
bun tsc   # works fine

Stack Trace

panic: runtime error: slice bounds out of range [:52400] with length 524

goroutine 1 [running]:
github.com/microsoft/typescript-go/scanner.(*Scanner).GetLineAndCharacterOfPosition(...)
        /Users/victor/go/pkg/mod/github.com/microsoft/typescript-go@v0.0.0-20250116223143-00ad56e4d9d7/scanner/scanner.go:3156
github.com/microsoft/typescript-go/scanner.GetLineAndCharacterOfPosition(...)
        /Users/victor/go/pkg/mod/github.com/microsoft/typescript-go@v0.0.0-20250116223143-00ad56e4d9d7/scanner/utilities.go:1222
github.com/microsoft/typescript-go/transformer.(*transformer).getJSONTypeArgument(0xc002c12240, 0xc0053084c0)
        /Users/victor/go/pkg/mod/github.com/microsoft/typescript-go@v0.0.0-20250116223143-00ad56e4d9d7/transformer/declarations.go:2172 +0x125

File

import "knex";

// Minimal reproduction of the module augmentation that causes tsgo panic
declare module "knex" {
  namespace Knex {
    interface QueryInterface<TRecord extends {} = any> {
      firstOrFail<TKey extends keyof TRecord>(
        ...columns: TKey[]
      ): Knex.QueryBuilder<TRecord, Pick<TRecord, TKey>> &
        Promise<Pick<TRecord, TKey>>;
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions