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
Copy file name to clipboardExpand all lines: README.md
+32-1Lines changed: 32 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -237,6 +237,37 @@ export const TYPE = {
237
237
> Since 1.0.0-beta.3 we use the symbol itself for indexing the dependencies.
238
238
> Prior to this version we indexed the dependencies by the string of the symbol.
239
239
240
+
## Type-Safe Token (2.0 beta)
241
+
242
+
With version 2 we added the possibility to use a type-safe way to identify our dependencies. This is done with tokens:
243
+
244
+
```ts
245
+
export TYPE = {
246
+
"Service" = token<MyServiceInterface>("Service"),
247
+
// [...]
248
+
}
249
+
```
250
+
251
+
In this case the type `MyServiceInterface` is inherited when using `container.get(TYPE.Service)`, `resolve(TYPE.Service)`
252
+
and `wire(this, "service", TYPE.Service)`and does not need to be explicitly added. In case of the decorator `@inject(TYPE.Service)` it needs to be added
253
+
but it throws a type error if the types don't match:
254
+
255
+
```ts
256
+
class Example {
257
+
@inject(TYPE.Service) // throws a type error because WrongInterface is not compatible with MyServiceInterface
0 commit comments