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

fix: isElementOfType Improved type inference #2099

Merged
merged 2 commits into from
Jun 25, 2024

Conversation

bmingles
Copy link
Contributor

@bmingles bmingles commented Jun 21, 2024

I missed the 2nd generic argument when I first wrote this util which made the type property resolve to string | React.JSXElementConstructor<any> in certain cases instead of the actual type. This should fix that.

resolves #2094

@bmingles bmingles requested a review from mofojed June 21, 2024 17:37
Copy link

codecov bot commented Jun 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 46.59%. Comparing base (a30341a) to head (8886d49).

Current head 8886d49 differs from pull request most recent head f1ccbb2

Please upload reports for the commit f1ccbb2 to get more accurate results.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2099   +/-   ##
=======================================
  Coverage   46.59%   46.59%           
=======================================
  Files         679      679           
  Lines       38598    38598           
  Branches     9779     9779           
=======================================
  Hits        17986    17986           
  Misses      20560    20560           
  Partials       52       52           
Flag Coverage Δ
unit 46.59% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bmingles bmingles changed the title feat: Improved type inference fix: Improved type inference Jun 21, 2024
@bmingles bmingles changed the title fix: Improved type inference fix: isElementOfType Improved type inference Jun 21, 2024
): node is ReactElement<InferComponentProps<T>> {
export function isElementOfType<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
T extends string | JSXElementConstructor<any> =
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious for learning purposes, what is the reasoning for having to separately extend string here, not any other types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Element types are either string or a factory function. e.g. 'div' | 'span' | SomeComponent. This also matches the signature of the ReactElement 2nd generic arg

): node is ReactElement<InferComponentProps<T>> {
export function isElementOfType<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
T extends string | JSXElementConstructor<any> =
Copy link
Member

Choose a reason for hiding this comment

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

Could have string | JSXElementConstructor<any> defined as a type above to make this a little nicer.

@bmingles bmingles merged commit e13c9d7 into deephaven:main Jun 25, 2024
13 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jun 25, 2024
@bmingles bmingles deleted the 2094-is-element-of-type branch July 2, 2024 22:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

isElementOfType - Not passing derived T type to ReactElement
3 participants