Skip to content

Make the fields of RequestInit optional. #381

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

Merged
merged 6 commits into from
Apr 29, 2020

Conversation

zakpatterson
Copy link
Contributor

@zakpatterson zakpatterson commented Sep 17, 2019

This way, users do not have to recite every field when creating a RequestInit. Also, the spec says the RequestInit dictionary must contain a field window which is set to null. We might as well include this too as a final variable, since the spec shows omitting it should be a type error.

Prompted by gitter conversation here: https://gitter.im/scala-js/scala-js?at=5d80415105fd3716953afa47

This way, users do not have to recite every field when creating a RequestInit.
Also, the spec says the RequestInit dictionary must contain a field `window`
which is set to null. We might as well include this too as a final variable,
since the spec shows omitting it should be a type error.
@zakpatterson
Copy link
Contributor Author

I see, however that @js.native traits are not supposed to have default definitions: https://www.scala-js.org/doc/interoperability/facade-types.html. Oddly this works with scala.js 1.0 and 0.6 on scala 2.12 and 2.13, but fails on 2.11 and 2[.yikes].10.

@flavomulti
Copy link

I think if you pull off the js.native this will work as expected though. Are you going to resubmit?

@zakpatterson
Copy link
Contributor Author

@flavomulti I just removed the js.native as you suggested. I remember now that I added that so that the window field could be set to null explicitly. Perhaps the way I have it now will work?

@flavomulti
Copy link

I think that as long as its not set, e.g. js.undefined, its ok not to specify it. If you do specify window, it must be null...something like that. It's never clear why funky things like this exist, but it is what it is.

It is ok if window is undefined, it just must not have a value other than `null` if defined.
@zakpatterson
Copy link
Contributor Author

Ah, that makes sense. So this will still throw a typeerror if a user tries to set it to something that's not null, which is what the spec wants. Ok thanks @flavomulti !

@aappddeevv
Copy link

Is there anyway to get this merged? With 1.0 out, we really need js.undefined on the RequestInit trait's properties as it is very unergonomic to use otherwise.

Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Sorry for being so late in answering this. Thanks for the PR.

I just have one comment below:

@sjrd
Copy link
Member

sjrd commented Apr 29, 2020

Thank you @zakpatterson

@sjrd sjrd changed the title Add default values for RequestInit fields Make the fields of RequestInit optional. Apr 29, 2020
@sjrd sjrd merged commit 0f6669a into scala-js:master Apr 29, 2020
@aappddeevv
Copy link

Thanks!

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

Successfully merging this pull request may close these issues.

4 participants