Skip to content

Consider making a Token class for types #9

Description

@justinmchase

Basically just a class to wrap a symbol and a Type so you can get inference through with your types.

e.g.

const token ExampleToken = new Token<IExample>("example") // Internally just has a Symbol("example")

interface IExample {
  run(): void;
}

@Service()
class A implements Iexample {
  public run(): void {
    console.log("A");
  }
}

// Service collection setup.
const serviceCollection = new ServiceCollection();
serviceCollection.addTransient(ExampleToken, A); // IExample is inferred as T from Token<T>

const services = serviceCollection.get(ExampleToken); // sevices is inferred as IExample

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions