Skip to content

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

@EladBezalel

Description

@EladBezalel

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.

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