Skip to content

All Optional Object Interface Converts to any #7485

Closed
@kitsonk

Description

@kitsonk

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.

Metadata

Metadata

Assignees

Labels

FixedA PR has been merged for this issueSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions