Papooch / nestjs-cls

A continuation-local storage (async context) module compatible with NestJS's dependency injection.
https://papooch.github.io/nestjs-cls/
MIT License
390 stars 23 forks source link

Cannot set complex objects with type inference #94

Closed rafagldev closed 6 months ago

rafagldev commented 6 months ago

When trying to set a complex object (e.g. a database connection object) the following error appears: Type instantiation is excessively deep and possibly infinite.ts(2589)

I could set this object with type inference, but it is a feature to nice to be lost.

Maybe there is other way to define the type of object without defining all possible fields in the tree structure. Could a type just be defined as the type itself, without any nesting?

Papooch commented 6 months ago

Please see this section of the docs.

In your case, define the store property as:

interface ClsStore {
 connection: Terminal<Connection>
}
rafagldev commented 6 months ago

Oh thank you! I must've skipped that section of the docs. Next time I'll read more thoroughly. 👍