I'm trying to utilize a named tuple (in this instance AnniversaryPropertyConfig) to describe a function argument in the following simplified code.
interface AnniversaryParameters {
value?: 'date-and-or-time' | 'text';
altid?: number | string;
calscale?: 'gregorian';
}
type AnniversaryPropertyConfig = [value: string, parameters?: AnniversaryParameters];
function main(config: AnniversaryPropertyConfig) {
return config;
}
const config = ['19960415', { value: 'text' as const }];
main(config);
However I keep receiving the following error: "Target requires 1 element(s) but source may have fewer.(2345)" I've tried to apply as const assertions to the config array and its values but to no avail. The error does go away if I typecast the config variable to the AnniversaryPropertyConfig type. But I feel like this is something that TypeScript should be able to infer without assistance.
For reference a link to an applicable TypeScript Playground can be found here.