question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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,

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
dilamecommented, Mar 19, 2021

Thank you! When are you planning the next release?

1reaction
NoNameProvidedcommented, Dec 2, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

typedi
fix : Using container.get/set methods with abstract class id.
Read more >
Abstract Class getter and setter usage
You need to create abstract getter and setter only if you need change behaviour of getiin and setting for your variables.
Read more >
Dependency injection in ASP.NET Core
Dependency injection addresses these problems through: The use of an interface or base class to abstract the dependency implementation.
Read more >
In Java, should I write setters and getters in abstract class ...
No, I wouldn't. Try this. Replace the setters with a constructor. Set the private data you need with this constructor. Replace the getters...
Read more >
Interfaces, Mixins and Building Powerful Custom Data ...
In Python, an interface is basically a specialized abstract class that defines one or more abstract methods. Abstract classes differs from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found