Skip to content

Strict object literal checking with union type #9470

Closed
@Lenne231

Description

@Lenne231

TypeScript Version: 1.8.0

Is this a bug or does it work as intended?

Code

type Test = { a: string; } | { b:number };

var t1 : Test = { a: '...', b: 3 }; // ok
var t2 : Test = { a: '...', b: '...' }; // ok but should be error!?
var t3 : Test = { a: '...', c: '...' }; // error

var a4 : { a: string; } = { a: '...', b: '...' }; // error

Expected behavior:
var t2 : Test = { a: '...', b: '...' }; should throw a compiler error as well because b is of type string and not number.

Actual behavior:
There is no compiler error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions