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

isElementOfType - Not passing derived T type to ReactElement #2094

Closed
bmingles opened this issue Jun 21, 2024 · 0 comments · Fixed by #2099 or deephaven/deephaven-core#5698
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@bmingles
Copy link
Contributor

The isElementOfType util is not currently providing the 2nd generic arg to ReactElement. This results in certain cases failing to narrow types which is the whole point of the type guard.

export function isElementOfType<T>(
  node: ReactNode,
  type: T
): node is ReactElement<InferComponentProps<T>> {
  return isValidElement(node) && node.type === type;
}

We should be able to fix this by constraining T a bit more and then passing it as the 2nd arg.

export function isElementOfType<
  T extends string | JSXElementConstructor<any> =
    | string
    | JSXElementConstructor<any>,
>(node: ReactNode, type: T): node is ReactElement<InferComponentProps<T>, T> {
  return isValidElement(node) && node.type === type;
}
@bmingles bmingles added bug Something isn't working triage Issue requires triage labels Jun 21, 2024
@bmingles bmingles self-assigned this Jun 21, 2024
bmingles added a commit to bmingles/web-client-ui that referenced this issue Jun 21, 2024
bmingles added a commit to bmingles/web-client-ui that referenced this issue Jun 21, 2024
@mofojed mofojed removed the triage Issue requires triage label Jun 25, 2024
@mofojed mofojed added this to the June 2024 milestone Jun 25, 2024
mofojed pushed a commit to deephaven/deephaven-core that referenced this issue Jul 4, 2024
Release notes
https://github.com/deephaven/web-client-ui/releases/tag/v0.84.0

### ⚠ BREAKING CHANGES

* - @deephaven/jsapi-components - The contract of
`useSearchableViewportData` to be more consistent with
`useViewportData`. `usePickerWithSelectedValues` now requires
`timeZone`.
- @deephaven/jsapi-utils - `createSearchTextFilter` requires `timeZone`

### Features

* useSearchableViewportData - support non-text filters
([#2092](deephaven/web-client-ui#2092))
([7009e21](deephaven/web-client-ui@7009e21)),
closes [#2102](deephaven/web-client-ui#2102)
[#2091](deephaven/web-client-ui#2091)


### Bug Fixes

* `isElementOfType` Improved type inference
([#2099](deephaven/web-client-ui#2099))
([e13c9d7](deephaven/web-client-ui@e13c9d7)),
closes [#2094](deephaven/web-client-ui#2094)
* Console does not scroll to bottom when code run from notebook
([#2114](deephaven/web-client-ui#2114))
([e75e716](deephaven/web-client-ui@e75e716))
* make textValue default to key for Normalized Item
([#2113](deephaven/web-client-ui#2113))
([bd3e944](deephaven/web-client-ui@bd3e944))
* Update IrisGridContextMenuHandler getHeaderActions return type to be
more permissive
([#2117](deephaven/web-client-ui#2117))
([4e08b79](deephaven/web-client-ui@4e08b79))

Co-authored-by: deephaven-internal <66694643+deephaven-internal@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants