const controlConfig = >T extends 'input' | 'button'(config: Config<T>): Config<T> => config;
interface Config<TYPE extends 'input' | 'button'> {
type: TYPE;
label: string;
popover?: string;
inputPlaceholder: TYPE extends 'input' ? string : never;
key: string;
}
const config: Config<'input' | 'button'>[][] = [
[
controlConfig({
type: 'button',
label: 'user',
popover: 'ID',
key: 'user',
}),
],
];
TS2345: Argument of type '{ type: "button"; label: string; popover: string; key: string; }' is not assignable to parameter of type 'Config<"button">'. Property 'inputPlaceholder' is missing in type '{ type: "button"; label: string; popover: string; key: string; }' but required in type 'Config<"button">'
If there is no easy solution or preference for using a type alias, why doesn't TypeScript have something like making properties optional based on conditions?