Papooch / nestjs-cls

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

tsc error 'Type instantiation is excessively deep and possibly infinite' when using AbortController #46

Closed micalevisk closed 1 year ago

micalevisk commented 1 year ago

I just create a new app with npx @nestjs/cli new that has the following src/app.service.ts:

import { Injectable } from '@nestjs/common';
import { ClsService, ClsStore } from 'nestjs-cls';

interface ClsStoreFoo extends ClsStore {
  foo: string;
  bar: AbortController; // If I drop this line, it works
}

@Injectable()
export class AppService {
  constructor(
    private readonly cls: ClsService<ClsStoreFoo>,
  ) {}
  getHello(): string {
    return this.cls.set('foo', '');
  }
}
src/app.service.ts:16:5 - error TS2589: Type instantiation is excessively deep and possibly infinite.

16     this.cls.set('foo', '');
       ~~~~~~~~~~~~~~~~~~~~~~~

When the store has some entry with the type AbortController, I got that a tsc error on ClsService#get and ClsService#set


micalevisk commented 1 year ago

solved by adding AbortController as a TerminalType below but I don't think this is the proper solution

https://github.com/Papooch/nestjs-cls/blob/d09c8e84a3a701cd80662ca0f8e7808d75533047/src/types/recursive-key-of.type.ts#L3-L16