-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Bug Report
When a function is typed to return an object of a certain type, the properties of the object can be expanded, meaning extra properties can be added to the ones described in the type or interface.
🔎 Search Terms
function return object type
🕗 Version & Regression Information
This is observable on the playground in all available versions.
Couldn't find anything I understood to be relevant in https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs
- This is a crash: No
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about interfaces and types of function return values
⏯ Playground Link
💻 Code
interface Result {
foo: string;
}
type Func = () => Result
const noError:Func = () => ({
foo: 'string1',
// @ts-expect-error
bar: 2,
});
const error:Func = (): Result => ({
foo: 'string1',
// @ts-expect-error
bar: 2,
});
const error2:Func = (): ReturnType<Func> => ({
foo: 'string1',
// @ts-expect-error
bar: 2,
});
🙁 Actual behavior
Extra properties in the returned object, which aren't defined in the interface or type, do not raise an error.
🙂 Expected behavior
Extra properties in the returned object, which aren't defined in the interface or type, should raise an error.
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created