Giter Site home page Giter Site logo

Comments (6)

deebloo avatar deebloo commented on July 16, 2024 1

Yes this would allow that. Till now I have just used a class with a "value" prop but this would allow any type.

from joist.

Phoscur avatar Phoscur commented on July 16, 2024

Could even put simple values in there?

const name = 'Grain';
const token = new InjectionToken(name); // would be nice to optionally give it a name
const providers = [{ provide: token, factory: () => 'Salt']

from joist.

deebloo avatar deebloo commented on July 16, 2024

One other note. Adding a default value would be optional. So this would be another way to require manually defending a provider.

from joist.

Phoscur avatar Phoscur commented on July 16, 2024

Found a minor issue with the new example in the readme (typescript is complaining), I hope this is related enough:

Type 'typeof Logger' is not assignable to type 'ProviderToken'.
Cannot assign an abstract constructor type to a non-abstract constructor type.ts(2322)
provider.d.ts(7, 5): The expected type comes from property 'provide' which is declared here on type 'Provider'

abstract class Logger {
  abstract log(...args: any[]): void;
}

const app = new Injector([
  {
    provide: Logger as ProviderToken<Logger>, // manual typecast to supress
    factory() {
      return console;
    }
  }
]);

from joist.

deebloo avatar deebloo commented on July 16, 2024

I'll double check the example locally. There should be no need to type cast anything. I think I just have the Logger class those wrong.

from joist.

deebloo avatar deebloo commented on July 16, 2024

@Phoscur ah the problem with the docs is the abstract token. I thought I had added the ability to support abstract classes but turns out that is missing from the provider definition. I updated the docs to reflect the correct usage.

from joist.

Related Issues (20)

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.