Skip to content

Strict object literal checking with union type #9470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Lenne231 opened this issue Jul 1, 2016 · 3 comments
Closed

Strict object literal checking with union type #9470

Lenne231 opened this issue Jul 1, 2016 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@Lenne231
Copy link

Lenne231 commented Jul 1, 2016

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.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jul 2, 2016

Linking to a previous discussion at #4452.

@DanielRosenwasser
Copy link
Member

@Lenne231 is there a specific scenario you were hit by this?

@mhegazy mhegazy added the Duplicate An existing issue was already created label Jul 11, 2016
@Lenne231
Copy link
Author

Lenne231 commented Aug 5, 2016

Not a specific scenario, i was just playing around with union types.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants