typescript - Utilizarea tipului `Parameters<>` Tipul 'T' nu respectă constrângerea
Încerc să „reexport” interfața evenimentelor către parametrii funcției sale: de exemplu
interface Events {
init: (value: string) => boolean,
end: (value: string, anotherValue: string) => void,
}
Rezultat așteptat:
interface EventsParams {
init: [value: string],
end: [value: string, anotherValue: string],
}
Ce fac:
import { Events } from './events';
export declare type EventsParams = {
[Property in keyof Events]: Parameters<Events[Property]>;
};
funcționează pentru mine în „dev”, dar în producție primesc:
error TS2344: Type 'Events[Property]' does not satisfy the constraint '(...args: any) => any'.
Type '((value: string) => void) | ((value: string) => void) | ((value: string) => void) | ((value: string) => void) | ((value: string) => void) | ((value: string) => void) | ... 75 more ... | undefined' is not assignable to type '(...args: any) => any'.
Type 'undefined' is not assignable to type '(...args: any) => any'.
[Property in keyof Events]: Parameters<Events[Property]>;
Ce îmi lipsește?