Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Clarify children for fragments and similar React APIs
Summary:
Before this change, a `Fragment`'s children were a non-optional maybe type,
which allows `void` but does not allow omitting the children property entirely.
Instead, the children should be optional. Since `React$Node` already includes
`null`, and `void` is not actually a valid child type, we can entirely replace
the maybe type with optionality.
The fragment expression `<></>` should be an error with a non-optional children
type, since at runtime the element will not be passed a children prop at all.
This worked by accident, since `Fragment` is defined as a function type and
function type's have an `any`-typed statics object, and thus `any` typed default
props.
In a stacked diff, I change function types to use a stricter type for statics
(an empty object with Function.prototype as the __proto__), which exposed this
bug.
Note that this bug also allowed creating a fragment with any children type,
e.g., `<>{() => {}}</>`, even though functions are not members of `React.Node`.
Reviewed By: bvaughn
Differential Revision: D14447780
fbshipit-source-id: db0cf4700cd97762b5c92b8a24ff5e0221c7ff96- Loading branch information
1 parent
b9e26fd
commit 6dd62e0
Showing
2 changed files
with
15 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters