Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 }>`.
- Loading branch information