Skip to content

Instantly share code, notes, and snippets.

@MadaraUchiha
Created July 12, 2020 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MadaraUchiha/d21010df5b2cec78bf2b1a3c4bcfb48f to your computer and use it in GitHub Desktop.
Save MadaraUchiha/d21010df5b2cec78bf2b1a3c4bcfb48f to your computer and use it in GitHub Desktop.
class ThingFactory {
constructor(private readonly service1: Service1, private readonly service2: Service2) {}
make<T extends OtherThing_1 | OtherThing_2>(arg: T) { // no need to declare return value. If you want to, it's T
// use this.service1 and this.service2 here
return arg;
}
}
const factory = new ThingFactory(service1, service2);
const thing = factory.make(new OtherThing_1()); // type of thing is OtherThing_1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment