-
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
fix #4 #5
fix #4 #5
Conversation
ebf1aec
to
d9b1c54
Compare
d9b1c54
to
8fe239f
Compare
Exceptional 👏 |
src/index.d.ts
Outdated
@@ -69,7 +69,7 @@ type ModuleAPI<Registry, PublicAPI extends Array<keyof Registry> = []> = { | |||
type ProviderFnArgs<Registry extends ObjectLike> = { | |||
[key in keyof ExternalDeps<Registry>]: | |||
| ExternalDeps<Registry>[key] | |||
| ((arg?: FlatDependencyTree<Registry>) => ExternalDeps<Registry>[key]); | |||
| ((arg?: InjectableMap<Registry>) => ExternalDeps<Registry>[key]); // technically there is no constraint on arg, it is quite the opposite: it may bring new constraints but this gets contrived. |
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 think arg
here should not be optional
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 think it should:
const createModule = createProvider({
injectables:{
someThing({random}: {random:number}) { return random * 42}
},
})
const myModule = createModule({
random() {
return Math.random();
}
})
should be ok
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.
Yes, if you make it mandatory your example above is still valid as
() => number
is compatible with
(arg: InjectableMap<Registry>) => ExternalDeps<Registry>['random']
On the other hand, this is not possible:
const createModule = createProvider({
injectables:{
someThing: ({ random }: { random: number }) => random * 42
randomMin: () => 100
},
})
const myModule = createModule({
random(injectables) => injectables?.randomMin +Math.random()
})
above, the injectables
type is InjectableMap<Registry> | undefined
, so we have to use the ?.
operator to access the value even if we know it will be defined (also because of that we can't destructure it).
Late bound factories will receive defined injectables.
Technically they could define new dependencies which would be resolved on the late as well, but this get contrived.