Previously with TypeScript 3.9+, this setup was functioning perfectly:
type keys =
| 'one'
| 'another'
| 'yet_another';
type variables = {
'another': { count: number }
'yet_another': { count: number, total: number }
};
export type TFunction = <T extends keys>(
key: T,
...args: T extends keyof variables ? [variables[T]] : []
) => string;
This allowed us to validate the arguments passed to the function.
t('one');
t('another', {count: 1});
However, following the latest update to Typescript 4, this configuration is no longer functional:
Expected 2 arguments, but got 1.
t('one');
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/interfaces.d.ts
...args: T extends keyof variables ? [variables[T]] : [];
Arguments for the rest parameter 'args' were not provided.
Do you have any suggestions on how to adjust it now?