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

fix: Made selector return types generic #1688

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { Grid, MockDataBarGridModel } from '@deephaven/grid';
import { ColorMap } from 'packages/grid/src/DataBarGridModel';
import type { ColorMap } from '@deephaven/grid';

function DataBarExample(): JSX.Element {
const columnData = [100, 50, 20, 10, -10, -20, -50, -30, 100, 0, 1];
Expand Down
4 changes: 2 additions & 2 deletions packages/iris-grid/src/IrisGridTableModelTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ import {
assertNotNull,
} from '@deephaven/utils';
import { TableUtils, Formatter, FormatterUtils } from '@deephaven/jsapi-utils';
import {
import type {
AxisOption,
DataBarOptions,
DirectionOption,
Marker,
ValuePlacementOption,
} from 'packages/grid/src/DataBarGridModel';
} from '@deephaven/grid';
import IrisGridModel from './IrisGridModel';
import AggregationOperation from './sidebar/aggregations/AggregationOperation';
import IrisGridUtils from './IrisGridUtils';
Expand Down
13 changes: 5 additions & 8 deletions packages/redux/src/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type {
CustomizableWorkspace,
RootState,
WorkspaceSettings,
} from './store';
import type { UndoPartial } from '@deephaven/utils';
import type { RootState, WorkspaceSettings } from './store';

const EMPTY_OBJECT = Object.freeze({});

Expand Down Expand Up @@ -52,15 +49,15 @@ export const getDefaultWorkspaceSettings = <State extends RootState>(
// Workspace
export const getWorkspace = <State extends RootState>(
store: State
): CustomizableWorkspace => {
): State['workspace'] => {
const { workspace } = store;
return workspace;
};

// Settings
export const getSettings = <State extends RootState>(
store: State
): WorkspaceSettings => {
): UndoPartial<State['workspace']['data']['settings']> => {
const customizedSettings = getWorkspace(store).data.settings;

const settings = { ...getDefaultWorkspaceSettings(store) };
Expand All @@ -72,7 +69,7 @@ export const getSettings = <State extends RootState>(
settings[key] = customizedSettings[key];
}
}
return settings;
return settings as UndoPartial<State['workspace']['data']['settings']>;
};

export const getDefaultSettings = <State extends RootState>(
Expand Down
7 changes: 7 additions & 0 deletions packages/utils/src/TypeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ export type OnlyOneProp<T> = {
[P in keyof T]: { [ONEPROP in P]: T[ONEPROP] };
}[keyof T];

/**
* Remove `Partial` wrapper from a type. Note that this is slightly different
* than `Required` because it will preserve optional properties on the original
* target type.
*/
export type UndoPartial<T> = T extends Partial<infer U> ? U : never;
Copy link
Member

Choose a reason for hiding this comment

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

Ohh neat


/**
* Util type to extract the value from an object.
*
Expand Down
Loading