GithubHelp home page GithubHelp logo

Comments (2)

wessberg avatar wessberg commented on August 29, 2024

Hey there,

So, I do have several questions based on your issue here.

  1. You use a method called load, but this library uses constructor injection. Did you mean to use the constructor?
  2. You use a type annotation, generic, but neither the load method nor the interface itself is generic. Which one is it?

Something that is now possible in v2.2.1 that wasn't possible before is to provide type arguments when declaring a service and its implementation:

interface MyInterface<T> {
}

container.registerSingleton<MyInterface<boolean>, MyClass>();
container.registerSingleton<MyInterface<boolean>, MyClass>();

Before, the compiler would assume that you wanted MyClass to only implement the service specifically called MyInterface<boolean> whereas now the service name is still just MyInterface.

from di-compiler.

cmidgley avatar cmidgley commented on August 29, 2024

FYI - type with generics (ie, IFoo<IBar>) work for registerSingleton and registerTransient but they do not work correct with get. The type is not stripped from the generated get call, leaving the full generic rather than just IFoo (in the example prior).

The issues appears to be here where:

node.typeArguments[0].getFullText().trim()

likely needs to be:

node.typeArguments[0].getFirstToken()!.getFullText().trim()

That change appears to work for me, though in the process I did notice that the tests extensively test the register calls, but do not do the same for get (and I don't think they cover types, but I didn't search all tests).

from di-compiler.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.