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

an optional property is giving an error when undefined (sealed, covariant object) #3692

Closed
gajus opened this issue Apr 10, 2017 · 2 comments
Closed
Assignees

Comments

@gajus
Copy link

gajus commented Apr 10, 2017

type RequestResponseType = {|
  
|};

type ResponseType = {|
  +encoding?: string
|};

const request = (): RequestResponseType => {
  return {};
};

const respond = (response: ResponseType) => {};

respond(request());
10:   return {};
             ^ object literal. Inexact type is incompatible with exact type
9: const request = (): RequestResponseType => {
                       ^ exact type: object type
13: const respond = (response: ResponseType) => {};
                               ^ property `encoding`. Property not found in
15: respond(request());
            ^ object type

https://goo.gl/iKKzI6

@gabelevi
Copy link
Contributor

@samwgoldman - this is another report of that thing I asked you about last week. Special casing the empty object bites us once again! I wonder if there's some way for us to seal the empty object when it's obviously not being modified.

@gajus - A possible workaround is return {encoding: undefined};

@vkurchatkin
Copy link
Contributor

Duplicate of #2977

@gajus gajus closed this as completed Apr 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants