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

Generics and TypeScript limited to 4.6.* #17

Closed
wants to merge 1 commit into from

Conversation

cmidgley
Copy link
Contributor

This pull addresses two things:

  1. Support for generics, as per Impossible to add in provider interfaces with generics.  #11.
  2. Limits TypeScript in package.json to ~4.6.4, as recently released 4.7 does not currently work. Obviously back out this change when 4.7 is supported.

Passes all tests, and change #1 has been in my rig for a couple months now.

I did bump the version number and add a change log. Sorry if this was inappropriate - some smaller projects like it when I assist with the details, others find it a major faux pas! In the change log I refer to the labeled version, which of course does not exist yet. Glad to fix the repo to remove that if you prefer.

Copy link
Owner

@wessberg wessberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR! I've looked through it and added a few comments :)

@@ -76,7 +76,7 @@
"crosspath": "^1.0.0",
"ts-node": "^10.8.0",
"npm-check-updates": "^13.0.3",
"typescript": "^4.6.4",
"typescript": "~4.6.4",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is just the development dependency of TypeScript, and won't restrict library consumers from installing and using TypeScript 4.7. If your intention is to restrict the consumer facing version of TypeScript, it will need to be addressed below it in the package.json file under peer dependencies. However, I would prefer not to do that, and instead look into what the root cause of this apparent regression may be.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree - my intent wasn't to fix the TS 4.7 issue, but to enable the tests to pass (and bring your attention to the 4.7 issue).
Glad to back this out - is that what you would prefer?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I would prefer that we look into this TS 4.7 issue you mention here, maybe in a separate issue ☺️ I'm definitely going to be needing v4.7 support myself soon anyway, so we might as well leave it in.

@@ -44,7 +44,7 @@ export function visitCallExpression(
factory.createPropertyAssignment(
"identifier",
factory.createStringLiteral(
node.typeArguments[0].getFullText().trim()
node.typeArguments[0].getFirstToken()!.getFullText().trim()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That NonNullAssertion there feels a bit unsafe. I would prefer that we handle it a bit more gracefully, ideally by taking the full text of the first token if it present, and falling back to taking the full text of the first type argument otherwise.
Something like:

// Move it up in a constant
const [firstTypeArgument] = node.typeArguments;

return factory.updateCallExpression(
          node,
          node.expression,
          node.typeArguments,
          [
            factory.createObjectLiteralExpression([
              factory.createPropertyAssignment(
                "identifier",
                factory.createStringLiteral(
                  (firstTypeArgument.getFirstToken()?.getFullText() ?? firstTypeArgument.getFullText()).trim()
                )
              ),
            ]),
          ]
        );

### Bug fixes

* Fixed issue with generics to allow `container.register<IService<Generic>, Service<Generic>>()`.
* Restricted `typescript` to minor version updates from `~4.6.4` as version 4.7 is currently incompatible.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changelog is actually auto-generated based on the commit log whenever a new version is released. So, unfortunately these two lines would actually be lost. To achieve the same result, you can write commit messages along these lines :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet. I'll back this out.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@cmidgley cmidgley closed this May 29, 2022
@cmidgley cmidgley deleted the origin branch May 29, 2022 10:30
@cmidgley
Copy link
Contributor Author

Sorry about the closures ... turns out git was very unhappy with my branch name (origin, stupid choice ... had to do with wanting to keep all my prior work and create a fresh branch origin to your code so I could create a clean pull for you). Renaming the branch caused github to close both PR's. New PR's coming...

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.

2 participants