fix type definition on useResizeObserver #326
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When using
useResizeObserver
, I discovered that the definition of the return type of this hook was misleading.DOMRect
is initialized toundefined
, and upon the first run of this hook, the return value can be undefined. In fact, the docs all show that you should check for the existence ofDOMRect
before doing anything with the return value. That should be reflected in the types.Related Issue
Fixes #325
Motivation and Context
TypeScript should be used to help consumers understand the potential values a variable could be. The return type of this function being inaccurate can cause consumers to inaccurately handle it and expect it to always be defined.
How Has This Been Tested?
Linked locally into my project using this function and verified that it correctly reported that it was potentially undefined.
Screenshots (if appropriate):