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

chore: updates to fix ts errors in v4.9.5 upgrade #176114

Closed
wants to merge 13 commits into from

Conversation

@nickofthyme nickofthyme added the WIP Work in progress label Feb 1, 2024
Copy link
Contributor Author

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

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

First batch of fixes, pretty confident in 😅

Merged in 0c669ff

Copy link
Contributor Author

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

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

Here is my attempt to fix x-pack/plugins/lens/public/datasources/form_based/operations/definitions/formula/formula.test.tsx.

See a20a96c.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These types are a little crazy but they are mocks trying to conform to multiple type definitions in a single function.

I reworked the types to pass a generic type based on the input type, with it defaulting to the field type.

This works for almost all cases, haven't checked other files 🤞🏼, except for used with the label: 'moving_average', see next comment 👇🏼 .

@@ -35,6 +35,7 @@ export interface ValueFormatConfig {
// Formatting can optionally be added to any column
export interface FormattedIndexPatternColumn extends BaseIndexPatternColumn {
params?: {
window?: number;
format?: ValueFormatConfig;
};
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When defining the moving average definition like here...

moving_average: createOperationDefinitionMock('moving_average', {
input: 'fullReference',
operationParams: [{ name: 'window', type: 'number', required: true }],
filterable: true,
getErrorMessage: jest.fn(() => ['mock error']),
buildColumn: ({ referenceIds }, columnsParams) => ({
label: 'moving_average',
dataType: 'number',
operationType: 'moving_average',
isBucketed: false,
scale: 'ratio',
timeScale: undefined,
params: { window: 5 },
references: referenceIds,
filter: getFilter(undefined, columnsParams),
}),
}),

The type of params: { window: 5 } is pointing to this type here thus why adding the window prop fixes the error.

But I think window type should be pulling from MovingAverageIndexPatternColumn instead which is here...

export type MovingAverageIndexPatternColumn = FormattedIndexPatternColumn &
ReferenceBasedIndexPatternColumn & {
operationType: typeof MOVING_AVERAGE_ID;
params: {
window: number;
};
};

Copy link
Contributor Author

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

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

The other two below are related and a bit more complex to solve.

  • x-pack/plugins/lens/public/editor_frame_service/editor_frame/workspace_panel/workspace_panel.tsx
  • x-pack/plugins/lens/public/embeddable/expression_wrapper.tsx

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These errors in both these files are due to the use of onData$. I believe the problem is that onData$ is declared as a generic function with 2 parameters, see below.

export interface ExpressionRendererParams extends IExpressionLoaderParams {
debounce?: number;
expression: string | ExpressionAstExpression;
hasCustomErrorRenderer?: boolean;
onData$?<TData, TInspectorAdapters>(
data: TData,
adapters?: TInspectorAdapters,
partial?: boolean
): void;
onEvent?(event: ExpressionRendererEvent): void;
onRender$?(item: number): void;
/**
* An observable which can be used to re-run the expression without destroying the component
*/
reload$?: Observable<unknown>;
}

Then when used like in ReactExpressionRendererType, it locks in the generic types for both TData and TInspectorAdapters, see here...

export type ReactExpressionRendererType = React.ComponentType<ReactExpressionRendererProps>;
export type ExpressionRendererComponent = React.FC<ReactExpressionRendererProps>;

But in both usages we set these types to a different type and typescript throws an error similar to...

Type 'TInspectorAdapters' is not assignable to type 'Partial<DefaultInspectorAdapters>'

@nickofthyme
Copy link
Contributor Author

Closing in favor of mistic#18 for simpler fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants