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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [2.2.7](https://github.com/wessberg/di-compiler/compare/v2.2.6...v2.2.7) (2022-5-26)

### 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!


## [2.2.6](https://github.com/wessberg/di-compiler/compare/v2.2.5...v2.2.6) (2021-11-19)


Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wessberg/di-compiler",
"version": "2.2.6",
"version": "2.2.7",
"description": "A Custom Transformer for Typescript that enables compile-time Dependency Injection",
"scripts": {
"generate:sandhog": "sandhog all --yes",
Expand Down Expand Up @@ -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.

"typescript-3-4-1": "npm:[email protected]",
"typescript-3-5-1": "npm:[email protected]",
"typescript-3-6-2": "npm:[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion src/transformer/before/visitor/visit-call-expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
                )
              ),
            ]),
          ]
        );

)
),
]),
Expand Down