Skip to content

Instantly share code, notes, and snippets.

@endel
Created January 19, 2019 14:31
Show Gist options
  • Save endel/cac781665ae408932b300739b816baec to your computer and use it in GitHub Desktop.
Save endel/cac781665ae408932b300739b816baec to your computer and use it in GitHub Desktop.
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