-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat(strongly-typed): initial commit #59
Conversation
9200964
to
e80b1d3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks great.
I added some suggestions, what do you think about them?
e80b1d3
to
0cfbdd1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks great!
I think we're almost done, we just need to handle this scenario and we're ready to merge it:
it('gets a promise', async () => {
// @ts-expect-error :: can't call get() to get Promise
expect(() => container.get('asyncNumber')).toThrow(
'it has asynchronous dependencies',
);
const n: Promise<number> = container.getAsync('asyncNumber'); // tsc complains
expect(await n).toBe(1);
});
0cfbdd1
to
941a810
Compare
This is amazing. Not sure why this is not offered by default. A lot of people are not going to find this when it's an extension, and TypeScript is almost used everywhere at this point. Can you elaborate on the thoughts of not having this in the main project? The generic type could just default to "any" or something similar. |
Hey @ffMathy, it's a long story. I could resume it in these bullet points:
As said, this is just a summary. Regarding visibility, I will update docs to give the visibility it deserves 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I saw a last minute issue, adding the comment.
I was about to do this myself but, would you mind adding an ESM build the same way we're actually doing with other modules? Otherwise I'll do it after we merge this.
Thank you so much for your great job!
: TKey extends interfaces.Abstract<infer D> | ||
? D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see this in preview reviews..., sry. Ok, interfaces.ServiceIdentifier<T>
no longer includes interfaces.Abstract<T>
. Instead, it includes the expected type Function
. Since Abstract<T>
was just a trick to exploit the any
type of a Function
, what about this:
: TKey extends interfaces.Abstract<infer D> | |
? D | |
: TKey extends Function | |
? any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay not entirely sure I follow, but have done this anyway since it matches upstream.
@notaphplover without changing anything my build now fails locally:
Did we change something upstream that I need to adapt to? The overly-aggressive commit hooks won't let me commit without fixing this. |
Hey @alecgibson , everything seems to be fine in th CI environment and mine.
git hooks are client side so, at the end, are optional. You can bypass then using the git commit --no-verify |
31fae7d
to
0727255
Compare
Add an initial offering for , which will let consumers optionally apply strong typing to their .
0727255
to
abf51a0
Compare
Thanks! Didn't know about this. (I've always found commit hooks a bit heavy-handed for my personal taste 🤷🏼 ). I've made the requested changes (I think? I wasn't sure what you meant about the ESM build; I just copied the Want to also make sure you're happy with the location of this library in the folder structure? |
So exciting! Great work everyone! 😍 |
The package seems to not be public somehow? If I go to https://www.npmjs.com/package/@inversifyjs/strongly-typed, I am taken to a login page. |
Hey @ffMathy, the package is not ready to be published. Additional PR are required to provide with |
Okay. Is this being worked on and tracked anywhere? And if not, is that something I can work on? |
For what it's worth I personally consider this |
This change builds on the work of the [`TypedContainer`][1] by adding type definitions for a strongly-typed `inject` decorator. [1]: inversify#59
This change builds on the work of the [`TypedContainer`][1] by adding type definitions for a strongly-typed `inject` decorator. [1]: inversify#59
|
This change builds on the work of the [`TypedContainer`][1] by adding type definitions for a strongly-typed `inject` decorator. [1]: inversify#59
Add an initial offering for
@inversifyjs/strongly-typed
, which will let consumers optionally apply strong typing to theirContainer
.