improve some grafana-ui types (#56318)

This commit is contained in:
Ashley Harrison 2022-10-05 09:04:10 +01:00 committed by GitHub
parent ae5e8bc53b
commit 7ac7f844f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 17 additions and 38 deletions

View File

@ -1279,9 +1279,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Do not use any type assertions.", "1"]
],
"packages/grafana-ui/src/components/FilterInput/FilterInput.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"packages/grafana-ui/src/components/FormattedValueDisplay/FormattedValueDisplay.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
@ -1887,36 +1884,16 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"]
],
"packages/grafana-ui/src/utils/reactUtils.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"packages/grafana-ui/src/utils/storybook/ThemedDocsContainer.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"packages/grafana-ui/src/utils/storybook/withTheme.tsx:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"packages/grafana-ui/src/utils/table.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"packages/grafana-ui/src/utils/useAsyncDependency.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
],
"packages/grafana-ui/src/utils/useCombinedRefs.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
],
"packages/grafana-ui/src/utils/useDelayedSwitch.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Do not use any type assertions.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
],
"packages/grafana-ui/src/utils/validate.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"]
],
"packages/jaeger-ui-components/src/ScrollManager.tsx:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Do not use any type assertions.", "1"],

View File

@ -16,8 +16,8 @@ export interface Props extends Omit<HTMLProps<HTMLInputElement>, 'onChange'> {
export const FilterInput = React.forwardRef<HTMLInputElement, Props>(
({ value, width, onChange, escapeRegex = true, ...restProps }, ref) => {
const innerRef = React.useRef<HTMLInputElement>(null);
const combinedRef = useCombinedRefs(ref, innerRef) as React.Ref<HTMLInputElement>;
const innerRef = React.useRef<HTMLInputElement | null>(null);
const combinedRef = useCombinedRefs<HTMLInputElement>(ref, innerRef);
const suffix =
value !== '' ? (

View File

@ -24,7 +24,7 @@ export function getChildId(children: ReactElement): string | undefined {
* @param itemToRender
* @param props props to be passed to the function if item provided as such
*/
export function renderOrCallToRender<TProps = any>(
export function renderOrCallToRender<TProps = {}>(
itemToRender: ((props?: TProps) => React.ReactNode) | React.ReactNode,
props?: TProps
): React.ReactNode {

View File

@ -1,13 +1,13 @@
// This is a temporary workaround to allow theme switching storybook docs
// see https://github.com/storybookjs/storybook/issues/10523 for further details
import { DocsContainer } from '@storybook/addon-docs';
import { DocsContainer, DocsContextProps } from '@storybook/addon-docs';
import React from 'react';
import { useDarkMode } from 'storybook-dark-mode';
import { GrafanaLight, GrafanaDark } from '../../../.storybook/storybookTheme';
type Props = {
context: any;
context: DocsContextProps;
};
export const ThemedDocsContainer: React.FC<Props> = ({ children, context }) => {

View File

@ -6,7 +6,7 @@ import { Field, LinkModel } from '@grafana/data';
* @internal
*/
export const getCellLinks = (field: Field, row: Row<any>) => {
let links: Array<LinkModel<any>> | undefined;
let links: Array<LinkModel<unknown>> | undefined;
if (field.getLinks) {
links = field.getLinks({
valueRowIndex: row.index,

View File

@ -1,10 +1,12 @@
import React from 'react';
export function useCombinedRefs<T>(...refs: any) {
const targetRef = React.useRef<T>(null);
export function useCombinedRefs<T>(
...refs: Array<React.MutableRefObject<T | null> | React.ForwardedRef<T | null> | ((instance: T | null) => void)>
) {
const targetRef = React.useRef<T | null>(null);
React.useEffect(() => {
refs.forEach((ref: any) => {
refs.forEach((ref) => {
if (!ref) {
return;
}

View File

@ -22,13 +22,13 @@ export function useDelayedSwitch(value: boolean, options: DelayOptions = {}): bo
const onStartTime = useRef<Date | undefined>();
useEffect(() => {
let timeout: number | undefined;
let timeout: ReturnType<typeof setTimeout> | undefined;
if (value) {
// If toggling to "on" state we always setTimeout no matter how long we have been "off".
timeout = setTimeout(() => {
onStartTime.current = new Date();
setDelayedValue(value);
}, delay) as any;
}, delay);
} else {
// If toggling to "off" state we check how much time we were already "on".
const timeSpent = onStartTime.current ? Date.now() - onStartTime.current.valueOf() : 0;
@ -40,7 +40,7 @@ export function useDelayedSwitch(value: boolean, options: DelayOptions = {}): bo
// We already spent enough time "on" so change right away.
turnOff();
} else {
timeout = setTimeout(turnOff, duration - timeSpent) as any;
timeout = setTimeout(turnOff, duration - timeSpent);
}
}
return () => {

View File

@ -7,12 +7,12 @@ export enum EventsWithValidation {
}
export const validate = (value: string, validationRules: ValidationRule[]) => {
const errors = validationRules.reduce((acc, currRule) => {
const errors = validationRules.reduce<string[]>((acc, currRule) => {
if (!currRule.rule(value)) {
return acc.concat(currRule.errorMessage);
}
return acc;
}, [] as string[]);
}, []);
return errors.length > 0 ? errors : null;
};