Skip to content

Generic with intersection: Could not match intersection against any of the possible combinations: [[]] #1764

@CodeSmith32

Description

@CodeSmith32

TSOA resolves the following type for Body correctly:

interface Foo {
  x: number;
  y: number;
}

@Route("/v1/foo")
class Foo extends Controller {
  @Post("/")
  async route(@Body() data: Partial<Foo> & Required<Pick<Foo, "x">>) {
    // ...
  }
}

But as soon as I try to make this type generic, TSOA breaks down:

interface Foo {
  x: number;
  y: number;
}

type OnlyRequire<T, U extends keyof T> = Partial<T> & Required<Pick<T, U>>;

type FooDto = OnlyRequire<Foo, "x">;

@Route("/v1/foo")
class Foo extends Controller {
  @Post("/")
  async route(@Body() data: FooDto) {
    // ...
  }
}

At this point, when the routes are generated, the validation model data appears something like follows, where the resulting type is a union of two objects with no properties in nestedProperties:

const models: TsoaRoute.Models = {
    "Partial_Foo_": {
        "dataType": "refAlias",
        "type": {"dataType":"nestedObjectLiteral","nestedProperties":{},"validators":{}}, // <----- No properties
    },
    // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
    "Required_Pick_Foo.x__": {
        "dataType": "refAlias",
        "type": {"dataType":"nestedObjectLiteral","nestedProperties":{},"validators":{}}, // <----- No properties
    },
    // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
    "OnlyRequire_Foo.x_": {
        "dataType": "refAlias",
        "type": {"dataType":"intersection","subSchemas":[{"ref":"Partial_Foo_"},{"ref":"Required_Pick_Foo.x__"}],"validators":{}},
    },
}

Thus, it doesn't crash when it runs, but any requests to this endpoint fail with a validation error:

Could not match intersection against any of the possible combinations: [[]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions