[react@18] More breaking type fixes (should be the last pr)#192266
[react@18] More breaking type fixes (should be the last pr)#192266Dosant merged 13 commits intoelastic:mainfrom
Conversation
| css={badgeCss} | ||
| > | ||
| {logLevel} | ||
| {logLevel as React.ReactNode} |
There was a problem hiding this comment.
logLevel is {} for some reason. Might be worth fixing on a level higher, but I didn't want to look into what would fail :)
| */ | ||
| export type Props = AllowedButtonProps & | ||
| AllowedPopoverProps & { | ||
| Omit<AllowedPopoverProps, 'children'> & { |
There was a problem hiding this comment.
We omit children from this type to properly replace using our custom type
| } | ||
|
|
||
| const NavigationWrapper: FC<Props & Partial<EuiCollapsibleNavBetaProps>> = (props) => { | ||
| const NavigationWrapper: FC<Props & Omit<Partial<EuiCollapsibleNavBetaProps>, 'children'>> = ( |
There was a problem hiding this comment.
We omit children from this type to properly replace using our custom type
| ) : ( | ||
| icon | ||
| // TODO: check this, icon might be a ComponentType | ||
| (icon as unknown as React.ReactNode) |
There was a problem hiding this comment.
The type allows ComponentType and this would render incorrectly in runtime. Worth following up (or feel free to improve in this PR)
There was a problem hiding this comment.
Thanks for the work on this @Dosant! 🙏
A couple of questions. Is the comment still needed?
Also, to clarify - are you saying that if the 'icon' is a component then it would not render correctly?
I believe this component is currently only used with icon types as strings (e.g. 'pencil') passed in. Should it be updated to not allow icon components to be passed in?
cc @qn895 for anything I may have missed.
There was a problem hiding this comment.
Hi! Thanks for looking.
Also, to clarify - are you saying that if the 'icon' is a component then it would not render correctly?
Yes!
The type of component allows ComponentType but it isn't handled properly during rendering. I put a TODO to call this out. If the ComponentType is not intended to be used, then the easier fix would be indeed to exclude it from the props. I'll take a look
| options={tokenOptions} | ||
| value={activeApiToken.type} | ||
| onChange={(e) => setTokenType(e.target.value)} | ||
| placeholder={i18n.translate( |
There was a problem hiding this comment.
See explanation in the PR description
| restrictWidth={false} | ||
| customPageSections | ||
| bottomBorder="extended" | ||
| docLink="inference_endpoints" |
There was a problem hiding this comment.
This prop didn't exist, hope I am not missing anything
| data-test-subj="settingsOutputsFlyout.kafkaVersionInput" | ||
| {...inputs.kafkaVersionInput.props} | ||
| options={kafkaVersionOptions} | ||
| placeholder={i18n.translate( |
There was a problem hiding this comment.
See explanation in the PR description
| <DragAndDropTextList | ||
| label={fieldsConfig.patterns.label!} | ||
| helpText={fieldsConfig.patterns.helpText} | ||
| helpText={ |
There was a problem hiding this comment.
this is follow-up to #192083
I missed it in the pr
| /> | ||
| </p> | ||
| <p>{missingFieldsMessage && missingFieldsMessage.longMessage}</p> | ||
| <p> |
There was a problem hiding this comment.
This is worth a follow-up (or feel free to help in this PR)
The longMessage is typed as React.ReactNode | ((closePopover: () => void) => React.ReactNode); but used in the most places simply as a ReactNode, which is incorrect
Ideally, this should simply be ReactNode or a typeof === function case should be handled with every render.
| const selectCaseModal = cases.hooks.useCasesAddToExistingCaseModal(); | ||
|
|
||
| return ( | ||
| <EuiPageTemplate template="empty"> |
There was a problem hiding this comment.
this prop didn't exist
| fullWidth | ||
| id="timeWindow" | ||
| error={errors.timeWindow} | ||
| error={errors.timeWindow as string[]} |
There was a problem hiding this comment.
A bunch of dummy casting is caused by this alerting error object that is typed as
export interface RuleFormParamsErrors {
[key: string]: string | string[] | RuleFormParamsErrors;
}
not sure if there is a better short term fix :(
There was a problem hiding this comment.
This should be fine, in practice this is only ever string[] 👍
|
Pinging @elastic/appex-sharedux (Team:SharedUX) |
jeramysoucy
left a comment
There was a problem hiding this comment.
Kibana security changes LGTM
szwarckonrad
left a comment
There was a problem hiding this comment.
DW/Osquery changes LGTM. Thanks!
| itemComponentProps={handleCardProps} | ||
| onChange={handlePaginationChange} | ||
| error={error} | ||
| error={error as React.ReactNode} |
There was a problem hiding this comment.
Perhaps consider tightening the type for the component props, as it seems that error on this side isn’t intended to be a ReactNode.
# Conflicts: # x-pack/plugins/lens/public/datasources/form_based/utils.test.tsx
awahab07
left a comment
There was a problem hiding this comment.
Obs UX Logs changes LGTM!
|
@elasticmachine merge upstream |
|
@elasticmachine merge upstream |
|
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: cc @Dosant |
logeekal
left a comment
There was a problem hiding this comment.
LGTM from investigations side. It is a bummer we have to do these castings but thanks for doing it. Just had a small question.
| ); | ||
|
|
||
| const onAlertTableUpdate: AlertsTableStateProps['onUpdate'] = useCallback( | ||
| const onAlertTableUpdate = useCallback<NonNullable<AlertsTableStateProps['onUpdate']>>( |
There was a problem hiding this comment.
May I ask why NonNullable is needed here and what was the problem with previous type?
There was a problem hiding this comment.
Sure! When assigned like this const onAlertTableUpdate: AlertsTableStateProps['onUpdate']
the argument in the function was implicitly any
to fix it, we assign like this: const onAlertTableUpdate = useCallback<AlertsTableStateProps['onUpdate']>
But this gives an error because AlertsTableStateProps['onUpdate'] could be undefined and it can't be used as a generic param. So with NonNullable we exclude undefined from that type
There was a problem hiding this comment.
Perfect. Thanks for explanation. I understand now.
Summary
Part of #138222
in @types/react@18 types DefinitelyTyped/DefinitelyTyped#56210. This PR addresses a bunch of remaining fixes (hopefully the last mass ping PR like this) The most common are:
1 Objects are no longer considered a valid ReactNode
In types@17 the ReactNode typing was too soft, it allowed objects and functions being passed as ReactNode, e.g.
This was by mistake, and this PR mutes most of such cases by simply casting to a
stringorReactNode.In some cases, it is worth to follow up and address the raised issues in a better way (see in comments)
function MyComponent() { const error: string | Error = 'Error' return ( <div> - {error} + {error as string} </div> ) }Most common problems are related to rendering errors, where it could be
string | Errorobject rendered directly as a ReactNode. Most often it is related to alerting framework:Not sure if there is a better fix then casting, surely not short-term.
2 More
useCallbackimplicit any fixesFollow up to #191659
3
EuiSelectdoesn't have a placeholder propIn a couple of places, the
placeholderprop was removed. This is because react types were updated andplaceholderwas removed from the base HTML element, so it highlighted places whereplaceholderprop was redundant