nicojs / typed-inject

Type safe dependency injection for TypeScript
Apache License 2.0
431 stars 23 forks source link

Support `as const` syntax for injection tokens #23

Closed reiv closed 3 years ago

reiv commented 4 years ago

Typescript 3.4 added a language feature to turn array literals into narrowly typed readonly tuples using the as const type assertion. It would improve the experience of typed-inject if we could use this syntax instead of having to import and use the tokens() helper function to specify dependencies. Right now it does not work because readonly arrays cannot be assigned to mutable arrays (which inject is assumed to be), so we get a type error in the provideXX() or injectXX() call.

As mentioned by @nicojs this would be a possible feature for a new (major) release.