Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/mapped generic type with date #1597

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jackey8616
Copy link
Collaborator

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you written unit tests?
  • Have you written unit tests that cover the negative cases (i.e.: if bad data is submitted, does the library respond properly)?
  • This PR is associated with an existing issue?

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
Copy link
Collaborator Author

@WoH need a rerun. thx

@jackey8616 jackey8616 requested a review from WoH March 22, 2024 14:41
@WoH
Copy link
Collaborator

WoH commented Mar 24, 2024

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
Copy link
Collaborator Author

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
Copy link
Collaborator

WoH commented Mar 24, 2024

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

@WoH
Copy link
Collaborator

WoH commented Mar 24, 2024

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
Copy link
Collaborator Author

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;
          }
        }
      });
  1. 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
Copy link
Collaborator

WoH commented Mar 30, 2024

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;
          }
        }
      });
  1. 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
Copy link
Collaborator Author

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?

Copy link

github-actions bot commented May 1, 2024

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

@github-actions github-actions bot added the Stale label May 1, 2024
@veiper93
Copy link

veiper93 commented May 5, 2024

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

@github-actions github-actions bot removed the Stale label May 6, 2024
@jackey8616
Copy link
Collaborator Author

@WoH Any news?

@WoH
Copy link
Collaborator

WoH commented May 23, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handling parameters that include mapped types with Date as a generic argument
3 participants