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(strongly-typed) allow use of generic helpers
Fixesinversify#170
At the moment it's impossible to create generic helper functions to
deal with `TypedContainer`:
```ts
interface MyMap {
foo: string;
}
function fn<T extends MyMap>(container: TypedContainer<T>) {
container.get('foo') // error
}
```
This is because of the `Synchronous` type that guards against calling
`.get()` on `Promise` bindings. Under the hood, this type is a mapped
type, which [doesn't work well with generics][1] (by design).
Rather than drop this guard all together, this change aims to strike a
balance by removing the `Synchronous` mapped type, and instead changing
the return type of synchronous `get()` methods to be `never` if the
binding is a `Promise`.
This won't error as obviously or as immediately as before, but will
still at least flag to the developer semantically that this binding will
never return a value (since it will throw), and should cause compilation
errors if consumers try to do anything with the returned value.
In return, we gain the ability to use generic helper functions.
[1]: microsoft/TypeScript#35647
0 commit comments