lukeautry / tsoa

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

Fix/mapped generic type with date #1597

Closed jackey8616 closed 2 weeks ago

jackey8616 commented 3 months ago

All Submissions:

Closing issues Closes #1596

Potential Problems With The Approach I'm not sure this fix will effect other not covered cases. Need folks to help me figure it out are there any possible missed cases.

jackey8616 commented 3 months ago

@WoH need a rerun. thx

WoH commented 3 months ago

Is this needed if the declaration is included? Usually we handle these high up in the type resolver (see: 'Promise').

I am generally very sceptical about these since they basically opt out of everything predictable.

jackey8616 commented 3 months ago

Is this needed if the declaration is included? Usually we handle these high up in the type resolver (see: 'Promise').

I am generally very sceptical about these since they basically opt out of everything predictable.

I'm not sure the meaning of declaration is included, could you give me more detail about it?

The error is cause by generic type name cannot determine if given T is Date.
Type resolve itself is working good. Once the calcRefTypeName could name it, everything works.

WoH commented 3 months ago

I am worried about any <T extends Date> where Date is not the one we now assume it is.

WoH commented 3 months ago

I briefly debugged this. We have declarations for Date, 6 of them actually. The fix should be in how we get the right one, not papering over a fix with another fix.

jackey8616 commented 3 months ago

I briefly debugged this. We have declarations for Date, 6 of them actually. The fix should be in how we get the right one, not papering over a fix with another fix.

I do noticed that there is 6 declarations (5 interface, 1 value). The error is cause by getModelTypeDeclarations omitted all typescript native library which Date is also included it.

Here comes 2 solutions:

  1. escape like this:
      modelTypes = modelTypes.filter(modelType => {
        // remove types that are from typescript e.g. 'Account'
        switch (typeName) {
          case 'Date':
            return modelType;
          default: {
            const srcFileName = modelType.getSourceFile().fileName;
            return srcFileName.replace(/\\/g, '/').toLowerCase().indexOf('node_modules/typescript') <= -1;
          }
        }
      });
  2. remove the filter I checked the definition of Date, found out that inside es2015, it seems nothing critical. Removing the filter is ok for all test cases.

Do you still remember anything about this native escape?

WoH commented 3 months ago

I briefly debugged this. We have declarations for Date, 6 of them actually. The fix should be in how we get the right one, not papering over a fix with another fix.

I do noticed that there is 6 declarations (5 interface, 1 value). The error is cause by getModelTypeDeclarations omitted all typescript native library which Date is also included it.

Here comes 2 solutions:

  1. escape like this:
      modelTypes = modelTypes.filter(modelType => {
        // remove types that are from typescript e.g. 'Account'
        switch (typeName) {
          case 'Date':
            return modelType;
          default: {
            const srcFileName = modelType.getSourceFile().fileName;
            return srcFileName.replace(/\\/g, '/').toLowerCase().indexOf('node_modules/typescript') <= -1;
          }
        }
      });
  2. remove the filter I checked the definition of Date, found out that inside es2015, it seems nothing critical. Removing the filter is ok for all test cases.

Do you still remember anything about this native escape?

Iirc there's a lot of bs in there. Basically all environments, as well as type declarations TS uses. Maybe we can decide based on the lib that is used from tsconfig. Otherwise we'd end up including a lot.

jackey8616 commented 3 months ago

Iirc there's a lot of bs in there. Basically all environments, as well as type declarations TS uses. Maybe we can decide based on the lib that is used from tsconfig. Otherwise we'd end up including a lot.

I'm not sure should we keep this line or not. I noticed that this line is exists at very beginning and add by Luke, and I've no idea why he wants to escape some type called Account like he commented with // remove types that are from typescript e.g. 'Account'. Also, there is no type named Account in es5 ~ es2023.

Shall we try remove this?

github-actions[bot] commented 2 months ago

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

veiper93 commented 2 months ago

Is there any indication of whether and when this pull request will be merged?

jackey8616 commented 2 months ago

@WoH Any news?

WoH commented 1 month ago

I have no clue, but removing and bumping a major version seems reasonable

github-actions[bot] commented 3 weeks ago

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

veiper93 commented 2 weeks ago

Will this be reopened and hopefully merged, or is it closed for good?