Skip to content

Commit

Permalink
fix: Made selector return types generic (#1688)
Browse files Browse the repository at this point in the history
fixes #1687
  • Loading branch information
bmingles authored Dec 12, 2023
1 parent ce7c33f commit b2972f0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
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;

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

0 comments on commit b2972f0

Please sign in to comment.