Skip to content
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

Type intersections between {} and types with only optional members are not type-checked. #8050

Closed
JabX opened this issue Apr 13, 2016 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@JabX
Copy link

JabX commented Apr 13, 2016

TypeScript Version:

  • typescript@next (1.9.0-20160412)
  • 1.8.9
  • and probably all the way down to the initial type intersection release.

Code

let test: {} & {foo?} & {bar?};
test = 'hello'; // Valid.

Expected behavior:
Well I'd like to have an error for that!

I get autocompletion for foo and bar while typing test = {}, but it's not enforced.

My use case is when I use a type in functions or classes like T & {foo?} with T = {}.

@JabX JabX changed the title Type unions between {} and types with only optional members are not type-checked. Type intersections between {} and types with only optional members are not type-checked. Apr 13, 2016
@Arnavion
Copy link
Contributor

Same as #7485 ?

@basarat
Copy link
Contributor

basarat commented Apr 13, 2016

Nothing special about intersection here. Any type with all optional members is considered compatible:

let test: {foo?:any;bar?:any;};
test = 'hello'; // Valid.

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Apr 13, 2016
@DanielRosenwasser
Copy link
Member

I think @Arnavion is correct (thanks a ton for digging that up!). Closing as a duplicate.

@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