What's the difference between these two ways of declaring arrow function in typescript?
type MyState = {
required: boolean;
optional?: boolean;
};
const myFn1: (s: MyState) => MyState = (s) => ({...s, unexpected: 1}) // no error
const myFn2 = (s: MyState): MyState => ({...s, unexpected: 1}) // error
myFn2 has the following error
Type '{ unexpected: number; required: boolean; optional?: boolean | undefined; }' is not assignable to type 'MyState'.
Object literal may only specify known properties, and 'unexpected' does not exist in type 'MyState'.
Why doesn't myFn1 have the same error?
Additionally, if I want this line
const myFn3: FnType = (s) => ({...s, unexpected: 1})
to give same error as myFn2, what should FnType be?