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

Invalid index error with indexed access of optional member of generic parameter constraint

Open 10xjs opened this issue 5 years ago • 3 comments

Given the example:

export interface MyGeneric<T extends { a?: string; b: number }> {
    a: T["a"];
    b: T["b"];
}

export interface MyObject extends MyGeneric<{ b: number }> {}

The following output is expected:

{
  "$ref": "#/definitions/MyObject",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "MyObject": {
      "additionalProperties": false,
      "properties": {
        "b": {
          "type": "number"
        }
      },
      "required": [
        "b"
      ],
      "type": "object"
    }
  }
}

However, the generator throws the following error:

Invalid index "a" in type "structure-896447058-143-156-896447058-132-157-896447058-124-157-896447058-97-160-896447058-0-161"

10xjs avatar Oct 11 '20 23:10 10xjs

I've added a test that reproduces this behavior here: https://github.com/vega/ts-json-schema-generator/commit/5773d322a13bf98fe2196edd374b6b408edd33b1

10xjs avatar Oct 11 '20 23:10 10xjs

Any progress on this issue ?

beast911 avatar Dec 30 '22 09:12 beast911

This issue is also happening with Hono, appears to be triggered by this line:

export class HonoRequest<P extends string = '/', I extends Input['out'] = {}> {

Where the Input type looks like this:

export type Input = {
  in?: {}
  out?: {}
}

only-cliches avatar Apr 15 '24 23:04 only-cliches