Skip to content

Commit

Permalink
chore: cleanup ts ignores (#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickofthyme authored Jan 13, 2021
1 parent b3f4f90 commit 40e6a8a
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 187 deletions.
10 changes: 9 additions & 1 deletion scripts/setup_enzyme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ configure({ adapter: new Adapter() });

process.env.RNG_SEED = 'jest-unit-tests';

declare global {
interface Window {
/**
* ResizeObserverMock override
*/
ResizeObserver: typeof ResizeObserverMock;
}
}

/**
* Mocking RAF and ResizeObserver to missing RAF and RO in jsdom
*/
Expand All @@ -50,5 +59,4 @@ class ResizeObserverMock {
disconnect() {}
}

// @ts-ignore
window.ResizeObserver = ResizeObserverMock;
2 changes: 0 additions & 2 deletions src/chart_types/heatmap/state/selectors/get_heatmap_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ export const getHeatmapTableSelector = createCachedSelector(
},
);

// FIXME, typing for mergeXDomain without seriesType
// @ts-ignore
resultData.xDomain = mergeXDomain([{ xScaleType: spec.xScaleType }], resultData.xValues, xDomain);

// sort values by their predicates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export const getRectangleRowGeometry: GetShapeRowGeometry<RectangleConstruction>

function rowSetComplete(rowSet: RowSet, measuredBoxes: RowBox[]) {
return (
!measuredBoxes.length &&
measuredBoxes.length === 0 &&
!rowSet.rows.some(
(r) => isNaN(r.length) || r.rowWords.length === 0 || r.rowWords.every((rw) => rw.text.length === 0),
)
Expand Down Expand Up @@ -314,7 +314,7 @@ export function getFillTextColor(
textContrast: TextContrast,
sliceFillColor: string,
containerBackgroundColor?: Color,
) {
): string | undefined {
const bgColorAlpha = isColorValid(containerBackgroundColor) ? chroma(containerBackgroundColor).alpha() : 1;
if (!isColorValid(containerBackgroundColor) || bgColorAlpha < 1) {
if (bgColorAlpha < 1) {
Expand All @@ -332,7 +332,7 @@ export function getFillTextColor(
);
}

let adjustedTextColor = textColor;
let adjustedTextColor: string | undefined = textColor;
const containerBackground = combineColors(sliceFillColor, containerBackgroundColor);
const textShouldBeInvertedAndTextContrastIsFalse = textInvertible && !textContrast;
const textShouldBeInvertedAndTextContrastIsSetToTrue = textInvertible && typeof textContrast !== 'number';
Expand All @@ -343,7 +343,6 @@ export function getFillTextColor(
if (textShouldBeInvertedAndTextContrastIsFalse || textShouldBeInvertedAndTextContrastIsSetToTrue) {
const backgroundIsDark = colorIsDark(combineColors(sliceFillColor, containerBackgroundColor));
const specifiedTextColorIsDark = colorIsDark(textColor);
// @ts-ignore
adjustedTextColor = getTextColorIfTextInvertible(
backgroundIsDark,
specifiedTextColorIsDark,
Expand Down Expand Up @@ -482,7 +481,7 @@ function tryFontSize<C>(
boxes: Box[],
maxRowCount: number,
) {
return function (initialRowSet: RowSet, fontSize: Pixels): { rowSet: RowSet; completed: boolean } {
return function tryFontSizeFn(initialRowSet: RowSet, fontSize: Pixels): { rowSet: RowSet; completed: boolean } {
let rowSet: RowSet = initialRowSet;

const wordSpacing = getWordSpacing(fontSize);
Expand Down Expand Up @@ -555,9 +554,9 @@ function tryFontSize<C>(
let rowHasRoom = true;

// iterate through words: keep adding words while there's room
while (measuredBoxes.length && rowHasRoom) {
while (measuredBoxes.length > 0 && rowHasRoom) {
// adding box to row
const currentBox = measuredBoxes[0];
const [currentBox] = measuredBoxes;

const wordBeginning = currentRowLength;
currentRowLength += currentBox.width + wordSpacing;
Expand All @@ -576,7 +575,7 @@ function tryFontSize<C>(

innerCompleted = rowSetComplete(rowSet, measuredBoxes);
}
const completed = !measuredBoxes.length;
const completed = measuredBoxes.length === 0;
return { rowSet, completed };
};
}
Expand Down
8 changes: 5 additions & 3 deletions src/chart_types/xy_chart/domains/x_domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/

import { Optional } from 'utility-types';

import { ScaleType } from '../../../scales/constants';
import { compareByValueAsc, identity } from '../../../utils/commons';
import { computeContinuousDataDomain, computeOrdinalDataDomain, Domain } from '../../../utils/domain';
Expand All @@ -35,7 +37,7 @@ import { XDomain } from './types';
* @internal
*/
export function mergeXDomain(
specs: Pick<BasicSeriesSpec, 'seriesType' | 'xScaleType'>[],
specs: Optional<Pick<BasicSeriesSpec, 'seriesType' | 'xScaleType'>, 'seriesType'>[],
xValues: Set<string | number>,
customXDomain?: DomainRange | Domain,
fallbackScale?: XScaleType,
Expand Down Expand Up @@ -177,13 +179,13 @@ export function findMinInterval(xValues: number[]): number {
* @internal
*/
export function convertXScaleTypes(
specs: Pick<BasicSeriesSpec, 'seriesType' | 'xScaleType' | 'timeZone'>[],
specs: Optional<Pick<BasicSeriesSpec, 'seriesType' | 'xScaleType' | 'timeZone'>, 'seriesType'>[],
): {
scaleType: XScaleType;
isBandScale: boolean;
timeZone?: string;
} | null {
const seriesTypes = new Set<string>();
const seriesTypes = new Set<string | undefined>();
const scaleTypes = new Set<ScaleType>();
const timeZones = new Set<string>();
specs.forEach((spec) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export const computeSeriesDomainsSelector = createCachedSelector(
deselectedDataSeries,
settingsSpec.xDomain,
settingsSpec.orderOrdinalBinsBy,
// @ts-ignore blind sort option for vislib
settingsSpec.enableVislibSeriesSort,
smallMultiples,
);
},
Expand Down
5 changes: 0 additions & 5 deletions src/chart_types/xy_chart/state/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ function getLastValues(dataSeries: DataSeries[], xDomain: XDomain): Map<SeriesKe
* @param deselectedDataSeries is optional; if not supplied,
* @param customXDomain is optional; if not supplied,
* @param orderOrdinalBinsBy
* @param enableVislibSeriesSort is optional; if not specified in <Settings />,
* then all series will be factored into computations. Otherwise, selectedDataSeries
* is used to restrict the computation for just the selected series
* @param smallMultiples
* @returns `SeriesDomainsAndData`
* @internal
Expand All @@ -200,14 +197,12 @@ export function computeSeriesDomains(
deselectedDataSeries: SeriesIdentifier[] = [],
customXDomain?: DomainRange | Domain,
orderOrdinalBinsBy?: OrderBy,
enableVislibSeriesSort?: boolean,
smallMultiples?: { vertical?: GroupBySpec; horizontal?: GroupBySpec },
): SeriesDomainsAndData {
const { dataSeries, xValues, seriesCollection, fallbackScale, smHValues, smVValues } = getDataSeriesFromSpecs(
seriesSpecs,
deselectedDataSeries,
orderOrdinalBinsBy,
enableVislibSeriesSort,
smallMultiples,
);
// compute the x domain merging any custom domain
Expand Down
Loading

0 comments on commit 40e6a8a

Please sign in to comment.