Skip to content

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

Open
@dilame

Description

@dilame

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,

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: fixedIssues with merged PRs, but not released yet.type: fixIssues describing a broken feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions