lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.42k stars 489 forks source link

6.0.0 regression: GenerateMetadataError: Unknown type: NeverKeyword #1535

Closed hpx7 closed 7 months ago

hpx7 commented 7 months ago

Sorting

Expected Behavior

In 5.1.1, tsoa was able to handle the following type (which represents an empty object, i.e. {})

Record<string, never>

Current Behavior

This breaks starting in 6.0.0-rc.0

There was a problem resolving type of 'Record<string, never>'.

Generate routes error.
 GenerateMetadataError: Unknown type: NeverKeyword
At unknown position...
This was caused by '<unknown name>'
    at TypeResolver.resolve (/project/node_modules/@tsoa/cli/src/metadataGeneration/typeResolver.ts:470:13)
    at <anonymous> (/project/node_modules/@tsoa/cli/src/metadataGeneration/typeResolver.ts:244:113)

Possible Solution

Steps to Reproduce

      1. 4.

Context (Environment)

Version of the library: 6.0.0 Version of NodeJS: 18.17.1

Detailed Description

Breaking change?

This is a breaking change in tsoa version 6

WoH commented 7 months ago

This was a bug in the old implementation, but we should support this.

hpx7 commented 7 months ago

@WoH I'm happy to try and contribute support for this, would you be able to provide any guidance for how this should be done?

WoH commented 7 months ago

This should result in:

{
  "type": "object",
  "properties": {
  },
  "additionalProperties": false
}

Right?

hpx7 commented 7 months ago

This is what it generates on 5.1.1:

    "Record_string.never_": {
        "properties": {},
        "type": "object",
        "description": "Construct a type with a set of properties K of type T"
    },
WoH commented 7 months ago

Since we are now trying to descend into the indexed type in a Mapped Type, we need to probably try to check if the indexType is the never type and handle that separately: https://github.com/lukeautry/tsoa/blob/master/packages/cli/src/metadataGeneration/typeResolver.ts#L242

hpx7 commented 7 months ago

Thanks for the tip, I created https://github.com/lukeautry/tsoa/pull/1537

WoH commented 7 months ago

Resolved in v6.0.1