I have the following issue, where the typescript compiler allows additional properties, that should not be allowed... I marked the line below. Basically the compiler allows additional properties of Command, while I thought they should not be allowed.
EDIT: Refactored self-contained example
type CommandData = { [key: string]: unknown }
type BaseState = { id: string; }
export type Command<
Type extends string = string,
Data extends CommandData = CommandData,
> = {
id: string;
payload: Data;
type: Type;
};
export type PreHook<StateModel extends BaseState = BaseState, Commands extends Command = Command> = ({
command,
state,
}: {
command: Commands;
state: StateModel;
}) => Promise<{ command: Commands; state: StateModel }>;
const preHook: PreHook = async ({ command, state }) => ({
command: { ...command, metadata: { foo: "bar" }, foo: "bar" }, // <-- METADATA AND FOO SHOULD NOT BE ALLOWED, BUT COMPILER DOES NOT ERROR
state: { ...state },
});