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

Make a few DOM properties nullable and IDL classes iterable #3127

Closed
wants to merge 2 commits into from

Conversation

loganfsmyth
Copy link
Contributor

These DOM properties are definitely nullable, though in the average case they probably exist. I assume it's best for the type definitions to cover all the possibilities.

For the iterability, Chome added these in a few releases ago and the next release of core-js should include polyfill logic for them. More info in zloirock/core-js#249

@gabelevi
Copy link
Contributor

gabelevi commented Jan 6, 2017

I find the argument made in the OP of zloirock/core-js#249 convincing. Definitely cool marking these as Iterable.

Other changes look good to me too! I'll get this merged! Thanks for the contribution!

@facebook-github-bot
Copy link
Contributor

@gabelevi has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@OlegLustenko
Copy link

How to use this syntax now ?

const body: HTMLElement = document.body;
// [flow] [flow] null (This type is incompatible with HTMLElement)
const body: HTMLElement | null = document.body;
body.addEventListener('mousemove', event, false);
// [flow] [flow] call of method `addEventListener` (Method cannot be called on possibly null value)

Should I'm run this way now ?

const body: HTMLElement | null = document.body;

From the documentation:

/* @flow */
var o: ?string = null;
if (o == null) {
  o = 'hello';
}
print(o.length);

Do I need to perform a null check?
What If I'm sure my code will execute when the body isn't null?

@loganfsmyth loganfsmyth deleted the type-fixes branch February 3, 2017 17:10
@loganfsmyth
Copy link
Contributor Author

You'd have to perform a null check, and either handle that case specifically, or throw so Flow knows that the value is guaranteed to exist after that point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants