Closed
Description
Bug Report
No error:
type CustomType = { name: string };
interface MyFunc {
(arg: string): CustomType;
}
const myFunc: MyFunc = (arg) => {
return { name: arg, extraKey: 1234 };
};
No error:
type CustomType = { name: string }
type MyFunc = (arg: string) => CustomType;
const myFunc: MyFunc = (arg) => {
return { name: arg, extraKey: 1234 };
};
Errors:
type CustomType = { name: string }
const myFunc = (arg: string): CustomType => {
return { name: arg, extraKey: 1234 };
};
// error: Type '{ name: string; extraKey: number; }' is not assignable to type 'CustomType'.
// Object literal may only specify known properties, and 'extraKey' does not exist in type 'CustomType'.
🔎 Search Terms
Function types not erroring when using type
or interface
.
🕗 Version & Regression Information
Version 4.2.3
Tested from version 3.3.3 to 4.2.3
⏯ Playground Link
N/A
Playground link with relevant code
💻 Code
See above
🙁 Actual behavior
Only the last example fails.
🙂 Expected behavior
All examples above should error. The function returns an object with incorrect keys.