-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already createdFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Description
TypeScript Version: [email protected]
Search Terms: return types accept extra properties
Code
interface IOnlyBob {bob :string};
//this errors as we expect
//const _errors :IOnlyBob = {bob:'hi', steve:'there'};
//this works fine but should error
let _returnsBob :() => IOnlyBob;
_returnsBob = () => ({bob:'hi', steve:'there'});
//I'd expect this to be the way to do the above, if that's what someone actually wanted
let _returnsNotJustBob :<T extends IOnlyBob>() => T;
_returnsNotJustBob = () => ({bob:'hi', steve:'there'} as any); //have to do any, see https://github.com/Microsoft/TypeScript/issues/28154
Expected behavior:
Line 8 should fail.
Type '{ bob: string; steve: string; }' is not assignable to type 'IOnlyBob'.
Object literal may only specify known properties, and 'steve' does not exist in type 'IOnlyBob'.
Actual behavior:
Works fine.
Playground Link: here
Related Issues:
snowl
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already createdFix AvailableA PR has been opened for this issueA PR has been opened for this issue