I have the following types
type CommonDic<Dic> = {
[I in keyof Dic]: {
[W in keyof Dic[I]]: string;
};
};
type MyDic = {
a: {
apple: string;
ant: string;
};
b: {
banana: string;
bear: string;
};
};
Problem
const getWord = <D extends CommonDic<D>, T extends keyof D, W extends keyof D[T]>(key: T, word: W) => {
return {
key,
word,
};
};
const word1 = getWord<MyDic>("a", "apple");
// error TS2558: Expected 3 type arguments, but got 1.
The code below works but any way to do this without currying?
const getWord2 =
<D extends CommonDic<D>>() =>
<T extends keyof D, W extends keyof D[T]>(key: T, word: W) => {
return {
key,
word,
};
};
const word2 = getWord2<MyDic>()("a", "apple"); // works
I've tried default type parameter but wasn't successful. Thanks!