tsoa icon indicating copy to clipboard operation
tsoa copied to clipboard

Generated spec does not match type passed to @Body

Open rosslavery opened this issue 2 years ago • 1 comments

Sorting

  • I'm submitting a ...

    • [x] bug report
  • I confirm that I

    • [x] used the search to make sure that a similar issue hasn't already been submit

Expected Behavior

Consider a utility type and example model as follows:

// Reusable utility type
type RepositoryFilterOptions<T> = {
  [P in keyof T]?: T[P] extends string | number ? T[P] | T[P][] : T[P];
};

// Example model
interface ListUser {
  id: string;
  age: number;
  active: boolean;
}

The TS compiler in editor properly understands the computed type as:

type ExampleListUser = RepositoryFilterOptions<ListUser>;

// Resulting type computation:
{
  id?: string | string[];
  age?: number | number[];
  active?: boolean;
}

image

Current Behavior

Currently, tsoa is understanding this type as if the T[P] extends string | number ? T[P] | T[P][] : T[P]; part of the utility type isn't there. It just infers the original type and uses that instead.

type ExampleListUser = RepositoryFilterOptions<ListUser>;

// Simulation of tsoa type computation:
{
  id: string;
  age: number;
  active: boolean;
}

Example spec output (incorrect based on above):

image

Version of the library: 4.1.3 Version of NodeJS: 16 LTS

  • Confirm you were using yarn not npm: [x]

rosslavery avatar Oct 21 '22 19:10 rosslavery