-
Notifications
You must be signed in to change notification settings - Fork 844
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
feat: TypeScript v5 prep work #7340
Conversation
ed236bc
to
d044f05
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a couple super minor nitty comments, all optional! I have 1-2 more higher level questions after this that I'll ask separately
@@ -146,7 +146,9 @@ export class EuiSideNav<T> extends Component<EuiSideNavProps<T>> { | |||
items={renderedItems} | |||
key={id} | |||
depth={depth} | |||
renderItem={renderItem} | |||
renderItem={ | |||
renderItem as PropsOf<typeof EuiSideNavItem>['renderItem'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[optional] Just curious, why not import EuiSideNavItemProps
directly and do EuiSideNavItemProps['renderItem']
? Does TS still yell about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The EuiSideNavItem
props type is defined as T extends _EuiSideNavItemButtonProps & _EuiSideNavItemProps & { renderItem?: (props: any) => JSX.Element }
, but the EuiSideNavItemProps
type is T extends { renderItem: Function } ? T & { renderItem: RenderItem<T> } : T
.
When working on that, I think I decided to keep the underlying component type the same and just use PropsOf
instead of updating renderItem
type to accept stricter RenderItem<T>
and EuiSideNavItemProps
export the props type of EuiSideNavItem
instead of being a weird conditional that I don't fully understand the necessity of.
I think the reason why renderItem
isn't included in _EuiSideNavItemProps
is because it's coming from the EuiSideNav
component and is meant to be only used internally, and EuiSideNavItem
component isn't exported as a public component. The way this is achieved, though, is really confusing, and I'd prefer to take a deeper look at it in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Super valid, thanks for explaining!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I only had nits! Feel free to address or ignore at your discretion. Would love answers to the below questions if you don't mind educating me!
upcoming_changelogs/7340.md
Outdated
- Updated generic types of `EuiBasicTable`, `EuiInMemoryTable` | ||
and `EuiSearchBar.Query.execute` to add `extends object` constraint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[attaching to a semi-random line for threading]
- If this resolves vscode's millions of problems every time I open up the basic table/memory table files, you are a god
- Can you ELI5 to me what changed here between TS 4 and TS 5 that made this change necessary? Is it just that TS 5 no longer auto infers the extend?
- The amount of
extends objects
s we had to add feels like a lot - I'm wondering if there's a more "Typescript-y" way to DRY that out (no worries if the answer is no, I'm just thinking out loud)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TS5 auto infers types as before, but the strict mode and overall type resolution work better now, reporting more errors where our types weren't strong enough to error out before. Adding these constraints fixes these implicit any
types
d044f05
to
b58dc38
Compare
…`false` to fix no type overlap typescript error
…ps object spread
…rops>` to `React.Children.map`
b58dc38
to
9c03df9
Compare
Preview staging links for this PR:
|
💚 Build Succeeded
History
cc @tkajtoch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look great - thanks so much for answering my questions!
`v91.3.1`⏩`v92.0.0-backport.0` --- ## [`v92.0.0-backport.0`](https://github.com/elastic/eui/releases/v92.0.0-backport.0) **This is a backport release only intended for use by Kibana.** **Bug fixes** - Fixed an `EuiTreeView` JSX Typescript error ([#7452](elastic/eui#7452)) - Fixed a color console warning being generated by disabled `EuiStep`s ([#7454](elastic/eui#7454)) ## [`v92.0.0`](https://github.com/elastic/eui/releases/v92.0.0) - Updated generic types of `EuiBasicTable`, `EuiInMemoryTable` and `EuiSearchBar.Query.execute` to add `extends object` constraint ([#7340](elastic/eui#7340)) - This change should have no impact on your applications since the updated types only affect properties that exclusively accept object values. - Added a new `EuiFlyoutResizable` component ([#7439](elastic/eui#7439)) - Updated `EuiTextArea` to accept `isClearable` and `icon` as props ([#7449](elastic/eui#7449)) **Bug fixes** - `EuiRange`/`EuiDualRange`'s track ticks & highlights now update their positions on resize ([#7442](elastic/eui#7442)) **Deprecations** - Updated `EuiFilterButton` to remove the second `.euiFilterButton__textShift` span wrapper. Target `.euiFilterButton__text` instead ([#7444](elastic/eui#7444)) **Breaking changes** - Removed deprecated `EuiNotificationEvent`. We recommend copying the component to your application if necessary ([#7434](elastic/eui#7434)) - Removed deprecated `EuiControlBar`. We recommend using `EuiBottomBar` instead ([#7435](elastic/eui#7435))
`v91.3.1`⏩`v92.0.0-backport.0` --- ## [`v92.0.0-backport.0`](https://github.com/elastic/eui/releases/v92.0.0-backport.0) **This is a backport release only intended for use by Kibana.** **Bug fixes** - Fixed an `EuiTreeView` JSX Typescript error ([elastic#7452](elastic/eui#7452)) - Fixed a color console warning being generated by disabled `EuiStep`s ([elastic#7454](elastic/eui#7454)) ## [`v92.0.0`](https://github.com/elastic/eui/releases/v92.0.0) - Updated generic types of `EuiBasicTable`, `EuiInMemoryTable` and `EuiSearchBar.Query.execute` to add `extends object` constraint ([elastic#7340](elastic/eui#7340)) - This change should have no impact on your applications since the updated types only affect properties that exclusively accept object values. - Added a new `EuiFlyoutResizable` component ([elastic#7439](elastic/eui#7439)) - Updated `EuiTextArea` to accept `isClearable` and `icon` as props ([elastic#7449](elastic/eui#7449)) **Bug fixes** - `EuiRange`/`EuiDualRange`'s track ticks & highlights now update their positions on resize ([elastic#7442](elastic/eui#7442)) **Deprecations** - Updated `EuiFilterButton` to remove the second `.euiFilterButton__textShift` span wrapper. Target `.euiFilterButton__text` instead ([elastic#7444](elastic/eui#7444)) **Breaking changes** - Removed deprecated `EuiNotificationEvent`. We recommend copying the component to your application if necessary ([elastic#7434](elastic/eui#7434)) - Removed deprecated `EuiControlBar`. We recommend using `EuiBottomBar` instead ([elastic#7435](elastic/eui#7435))
Summary
This PR adds the code changes needed for TypeScript v5 to work with EUI and not report any type errors.
I'm not upgrading to
typescript
version 5 here. It requires additional work to getprop-loader.js
updated to use the new compiler API and will be added in a separate PR.QA
General checklist
@default
if default values are missing) and playground toggles