Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

All Optional Object Interface Converts to any #7485

Copy link
Copy link
@kitsonk

Description

@kitsonk
Issue body actions

I couldn't find a relevant issue, but this does seem rather fundamental and against the principle of:

  1. Statically identify constructs that are likely to be errors.

TypeScript Version:

1.8.7

Code

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.

Reactions are currently unavailable

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

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.