I was hoping that giving a default value to a generic will take precedence over type inference, but it doesn't:
// placeholder for a real express response.send
const sendResponse = (x) => console.log(x);
function sendResult<T = never>(send: any, result: T) {
send(result);
}
// I want to use this always with a type
type Num = { x: number };
sendResult<Num>(sendResponse, { x: 1 });
sendResult<Num>(sendResponse, { x: 'sss' }); // correctly showing error
// When I don't supply type, I'd like an error.
// But, T gets inferred instead of defaulting to never... so, no error :-(
sendResult(sendResponse, {x: 1})
Is there a way to make sure an error is thrown if generic is not provided?
Typescript version: 3.5.2