I'm guessing I'm not doing something quite right, but I'm not sure what it is.
I'm wanting to write a type that describes a function and it's return type.
type SomeFn<Output extends Record<string, any>> = ( x: Record<string, any> ) => Output
But when I use it, I don't get errors when I would expect them.
type ExpectedOutput = { num1: number }
const testFn1: SomeFn<ExpectedOutput> = x => ( { foo: 'foo', num1: 1 } )
// should error, but doesn't ^^^^^^^^^^
const testFn2: SomeFn<ExpectedOutput> = x => {
const data = { foo: 'foo', num1: 1 }
return data
// ^^^^ should error, but doesn't
}
What am I doing wrong?