I want to a way pass myG
to Foo
and get completions(in vscode) for Foo.get
and for the OBJ
/KEY_OF_OBJ
constructor arg, i can get it to work so that i get completions for Foo.get
or for OBJ
/KEY_OF_OBJ
, but not all at the same time.
interface G {
[key: string]: string;
}
interface GE<T extends G> {
[key: string]: T;
}
class Foo<T extends G, K extends GE<T>> {
constructor(OBJ: K, KEY_OF_OBJ: keyof K) {}
get(keyOfG: keyof T) {}
}
interface myG extends G {
d: string;
e: string;
}
const foo = new Foo<myG>(
{
a: {
d: '',
e: ''
},
c: {
d: '',
e: ''
}
},
'c'
);
foo.get('');
edit:
having to declare Foo
like this new Foo<myG, {a: myG, c: myG}>
is also acceptable, my only issue with declaring it like this is, that Foo.get
doesn't get autocompletion which is because of the ts thinks its a string thing, if i remove G
, it works, but i want T
to have key: stringValue
pairs, i guess my problem is kind of solved, unless there is a way to constrain T
to only have string values.