ts-json-schema-generator
ts-json-schema-generator copied to clipboard
Error: Invalid index "length" in type "[]"
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
- Create a file with this content:
export type Test = []['length']; - 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.