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

feat: TypeScript v5 prep work #7340

Merged
merged 15 commits into from
Dec 21, 2023
Merged

feat: TypeScript v5 prep work #7340

merged 15 commits into from
Dec 21, 2023

Conversation

tkajtoch
Copy link
Member

@tkajtoch tkajtoch commented Nov 3, 2023

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 get prop-loader.js updated to use the new compiler API and will be added in a separate PR.

QA

  • Build this branch locally and use it in a local kibana instance to ensure there are no type errors there

General checklist

  • Docs site QA
  • Code quality checklist
  • Release checklist
    • A changelog entry exists and is marked appropriately.
    • If applicable, added the breaking change issue label (and filled out the breaking change checklist)

@tkajtoch tkajtoch self-assigned this Nov 3, 2023
@tkajtoch tkajtoch requested a review from a team as a code owner November 3, 2023 16:14
This was referenced Nov 6, 2023
Copy link
Member

@cee-chen cee-chen left a 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

upcoming_changelogs/7340.md Outdated Show resolved Hide resolved
src/utils/prop_types/is.ts Outdated Show resolved Hide resolved
src/utils/prop_types/is.ts Outdated Show resolved Hide resolved
@@ -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']
Copy link
Member

@cee-chen cee-chen Nov 6, 2023

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?

Copy link
Member Author

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.

Copy link
Member

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!

src/components/markdown_editor/markdown_editor.tsx Outdated Show resolved Hide resolved
Copy link
Member

@cee-chen cee-chen left a 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!

Comment on lines 1 to 2
- Updated generic types of `EuiBasicTable`, `EuiInMemoryTable`
and `EuiSearchBar.Query.execute` to add `extends object` constraint
Copy link
Member

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]

  1. If this resolves vscode's millions of problems every time I open up the basic table/memory table files, you are a god
  2. 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?
  3. The amount of extends objectss 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)

Copy link
Member Author

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

@kibanamachine
Copy link

Preview staging links for this PR:

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @tkajtoch

Copy link
Member

@cee-chen cee-chen left a 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!

@tkajtoch tkajtoch merged commit a1b5168 into main Dec 21, 2023
7 checks passed
@tkajtoch tkajtoch deleted the feat/typescript-5-prep branch December 21, 2023 13:06
@cee-chen cee-chen mentioned this pull request Jan 9, 2024
1 task
cee-chen added a commit to elastic/kibana that referenced this pull request Jan 10, 2024
`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))
delanni pushed a commit to delanni/kibana that referenced this pull request Jan 11, 2024
`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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants