-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
FixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
I couldn't find a relevant issue, but this does seem rather fundamental and against the principle of:
- Statically identify constructs that are likely to be errors.
TypeScript Version:
1.8.7
interface Optional {
foo?: string;
}
function foo(o: Optional): void {}
foo('bar'); // should throw
foo(1); // should throw
foo({ bar: 'baz' }); // should (and does) throw
Expected behavior:
Expected behaviour is that you should be able to type guard against other non-objects and only accept Objects with no properties or declared properties.
Actual behavior:
Passing anything other than an object literal that contains extra properties is acceptable.
Bobris, jwbay, JabX, spalger, plantain-00 and 23 more
Metadata
Metadata
Assignees
Labels
FixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript