Required Arguments in TypeScript Functions

This will compile in TypeScript:

type Func = (arg1: number, arg2: string) => void;

const F: Func = (arg1) => {
  console.log(arg1);
};

F(1, "hello");

This is historical baggage of the way JavaScript handles function arguments (read: its braindead). This is historical baggage of JavaScript being made in ten days.

The only way to have TypeScript enforce parameters properly you need to use an object as the parameter type.

The following will (thankfully) fail to compile:

type Func = ({arg1: number; arg2: string}) => void;

const F: Func = ({ arg1 }) => {
  console.log(arg1);
};

F({ arg1: 1, arg2: "hello"});