Created
January 19, 2019 14:31
-
-
Save endel/cac781665ae408932b300739b816baec 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
interface Serializer<State, API= any> { | |
getState() : State; | |
getAPI() : API; | |
} | |
class MyAPI<State> { | |
state: State; | |
my() {} | |
api() {} | |
methods() {} | |
here() {} | |
} | |
class MySerializer<State> implements Serializer<State, MyAPI<State>> { | |
api = new MyAPI<State>(); | |
getState() { | |
return this.api.state; | |
} | |
getAPI() { | |
return this.api; | |
} | |
} | |
class AllowCustomSerializer<T= any, S extends Serializer<T> = MySerializer<T>> { | |
serializer: S; | |
get api() { | |
return this.serializer.getAPI(); | |
} | |
} | |
interface MyState {} | |
const instance = new AllowCustomSerializer<MyState, MySerializer<MyState>>(); | |
instance.serializer.getAPI() // type of `API` | |
instance.api // type of `any` 😢 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment