typedi icon indicating copy to clipboard operation
typedi copied to clipboard

fix: Using container.get/set methods with abstract class id

Open dilame opened this issue 4 years ago • 7 comments

Description

Here is the error message

TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type 'typeof IgpapiHttp' is not assignable to parameter of type 'ServiceIdentifier<unknown>'.
      Type 'typeof IgpapiHttp' is not assignable to type 'Constructable<unknown>'.
        Cannot assign an abstract constructor type to a non-abstract constructor type.
src/igpapi.ts (56:24)

56     this.container.set(IgpapiHttp, http);
                          ~~~~~~~~~~

  ../../node_modules/typedi/types/container-instance.class.d.ts:50:5
    50     set<T = unknown>(token: ServiceIdentifier, instance: T): this;
           ~~~
    The last overload is declared here.

Here is the same error screenshot (maybe it's more comfortable to read the colored text for someone)

Снимок экрана 2021-02-24 в 20 05 58

Minimal code-snippet showcasing the problem


abstract class Foo {}

const container = new ContainerInstance('');

container.set(Foo, 1)

It doesn't work for TypeScript "strict": true mode,

dilame avatar Feb 24 '21 17:02 dilame

Hmm, this should work. I will need to take a look. Thanks for the report.

NoNameProvided avatar Mar 09 '21 07:03 NoNameProvided

Fixed in https://github.com/typestack/typedi/commit/aff2542f7e81383d1c9613109fdef2825b5c7619. It will be included in the next release.

NoNameProvided avatar Mar 09 '21 07:03 NoNameProvided

Thank you! When are you planning the next release?

dilame avatar Mar 19 '21 13:03 dilame

@NoNameProvided Is there any update on the next release?

finwo avatar Nov 22 '22 12:11 finwo

Hi! I am focusing on class-validator currently, but I will try to pick up the reins here as well and see what will be released and make it happen.

NoNameProvided avatar Dec 02 '22 10:12 NoNameProvided

@NoNameProvided hey, any update on this release? I just hit the same issue

viict avatar May 25 '23 01:05 viict

I eventually abandoned the library in favor of writing my own.

finwo avatar May 25 '23 08:05 finwo