You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix published provideClass return type inference. (#14)
Without the type assertion, compiler resulting npm package type
definition for `provideClass` looks like:
```
providesClass: <Token extends TokenType, Service, Tokens extends readonly ValidTokens<Services>[]>(token: Token, cls: InjectableClass<Services, Service, Tokens>) => Container<AddService<Services, Token, import("./Injectable").ConstructorReturnType<InjectableClass<Services, Service, Tokens>>>>;
```
The last bit (`ConstructorReturnType<InjectableClass<Services, Service,
Tokens>>>>`) is somehow problematic. Resolving types for services
provided using the function breaks, e.g.
`container.providesClass('serivice', Service)` returns a container of
type `Container<{ service: any }>`.
The fix addresses the issue by asserting the function's return type, so
the generated function signature looks like:
```
providesClass: <Token extends TokenType, Service, Tokens extends readonly ValidTokens<Services>[]>(token: Token, cls: InjectableClass<Services, Service, Tokens>) => Container<AddService<Services, Token, Service>>;
```
With that `container.providesClass('serivice', Service)` correctly
returns a container of type `Container<{ service: Service }>`.
0 commit comments