Created
July 12, 2020 07:14
-
-
Save MadaraUchiha/d21010df5b2cec78bf2b1a3c4bcfb48f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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