ts-json-schema-generator icon indicating copy to clipboard operation
ts-json-schema-generator copied to clipboard

Error: Invalid index "length" in type "[]"

Open EladBezalel opened this issue 5 months ago • 2 comments

Bug: Invalid index "length" in type "[]"

Description

When running ts-json-schema-generator on a file containing the following TypeScript type:

export type Test = []['length'];

the tool throws an error:

Invalid index "length" in type "[]"

Steps to Reproduce

  1. Create a file with this content:
    export type Test = []['length'];
    
  2. Run:
    npx ts-json-schema-generator --path file.ts --type Test
    

Real-World Usage Example

We encountered this issue while using the IntRange type from the type-fest package.
IntRange relies on tuple length indexing as part of its type-level computation. For example:

import { IntRange } from 'type-fest';

type Range = IntRange<0, 10>; // 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Internally, IntRange and similar utilities use expressions like []['length'] to compute numeric ranges.
This means the inability to handle such indexed access types prevents us from generating JSON schemas for types that depend on IntRange and similar utilities.

EladBezalel avatar May 19 '25 11:05 EladBezalel