fix: types

This commit is contained in:
Fine 2023-04-06 15:37:01 +08:00
parent 4acfc6eeaf
commit 09a7789c1c
18 changed files with 45 additions and 37 deletions

View File

@ -30,13 +30,13 @@ function validateFileName(str: string): string | undefined {
Object.keys(requireComponent).forEach((filePath: string) => { Object.keys(requireComponent).forEach((filePath: string) => {
const fileName = validateFileName(filePath); const fileName = validateFileName(filePath);
if (fileName) { if (fileName) {
result[fileName] = (requireComponent as { [key: string]: any })[filePath].default; result[fileName] = (requireComponent as Indexable)[filePath].default;
} }
}); });
Object.keys(requireTool).forEach((filePath: string) => { Object.keys(requireTool).forEach((filePath: string) => {
const fileName = validateFileName(filePath); const fileName = validateFileName(filePath);
if (fileName) { if (fileName) {
t[fileName] = (requireTool as { [key: string]: any })[filePath].default; t[fileName] = (requireTool as Indexable)[filePath].default;
} }
}); });

View File

@ -162,7 +162,7 @@ limitations under the License. -->
import { computed, onMounted, watch, reactive } from "vue"; import { computed, onMounted, watch, reactive } from "vue";
import type { PropType } from "vue"; import type { PropType } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
/*global defineProps, defineEmits */ /*global defineProps, defineEmits, Indexable, Recordable */
const emit = defineEmits(["input", "setDates", "ok"]); const emit = defineEmits(["input", "setDates", "ok"]);
const { t } = useI18n(); const { t } = useI18n();
const props = defineProps({ const props = defineProps({
@ -191,7 +191,7 @@ limitations under the License. -->
minute: 0, minute: 0,
second: 0, second: 0,
}); });
const get = (time: Date): { [key: string]: any } => { const get = (time: Date): Indexable => {
return { return {
year: time.getFullYear(), year: time.getFullYear(),
month: time.getMonth(), month: time.getMonth(),
@ -390,7 +390,7 @@ limitations under the License. -->
state.year--; state.year--;
} }
}; };
const is = (e: any) => { const is = (e: Recordable) => {
return e.target.className.indexOf(`${state.pre}-date-disabled`) === -1; return e.target.className.indexOf(`${state.pre}-date-disabled`) === -1;
}; };
const ok = (info: any) => { const ok = (info: any) => {

View File

@ -46,7 +46,7 @@ limitations under the License. -->
import Trace from "@/views/dashboard/related/trace/Index.vue"; import Trace from "@/views/dashboard/related/trace/Index.vue";
import associateProcessor from "@/hooks/useAssociateProcessor"; import associateProcessor from "@/hooks/useAssociateProcessor";
/*global Nullable, defineProps, defineEmits*/ /*global Nullable, defineProps, defineEmits, Indexable*/
const emits = defineEmits(["select"]); const emits = defineEmits(["select"]);
const { t } = useI18n(); const { t } = useI18n();
const chartRef = ref<Nullable<HTMLDivElement>>(null); const chartRef = ref<Nullable<HTMLDivElement>>(null);
@ -62,7 +62,7 @@ limitations under the License. -->
height: { type: String, default: "100%" }, height: { type: String, default: "100%" },
width: { type: String, default: "100%" }, width: { type: String, default: "100%" },
option: { option: {
type: Object as PropType<{ [key: string]: any }>, type: Object as PropType<Indexable>,
default: () => ({}), default: () => ({}),
}, },
filters: { filters: {

View File

@ -76,7 +76,7 @@ limitations under the License. -->
function handleClick() { function handleClick() {
visible.value = false; visible.value = false;
} }
function setPopper(event: any) { function setPopper(event: MouseEvent) {
event.stopPropagation(); event.stopPropagation();
visible.value = !visible.value; visible.value = !visible.value;
} }

View File

@ -40,7 +40,7 @@ limitations under the License. -->
// value: string | number; // value: string | number;
// } // }
/*global defineProps, defineEmits*/ /*global defineProps, defineEmits, Indexable*/
const emit = defineEmits(["change", "query"]); const emit = defineEmits(["change", "query"]);
const props = defineProps({ const props = defineProps({
options: { options: {
@ -53,7 +53,7 @@ limitations under the License. -->
default: () => [], default: () => [],
}, },
value: { value: {
type: [Array, String, Number, undefined] as PropType<any>, type: [Array, String, Number, undefined] as PropType<unknown>,
default: () => [], default: () => [],
}, },
size: { type: null, default: "default" }, size: { type: null, default: "default" },
@ -71,7 +71,7 @@ limitations under the License. -->
const selected = ref<string[] | string>(props.value); const selected = ref<string[] | string>(props.value);
function changeSelected() { function changeSelected() {
const options = props.options.filter((d: any) => const options = props.options.filter((d: Indexable) =>
props.multiple ? selected.value.includes(d.value) : selected.value === d.value, props.multiple ? selected.value.includes(d.value) : selected.value === d.value,
); );
emit("change", options); emit("change", options);

View File

@ -241,7 +241,7 @@ limitations under the License. -->
} }
dates.value[0] = d; dates.value[0] = d;
}; };
const dc = (e: any) => { const dc = (e: MouseEvent) => {
show.value = (datepicker.value as any).contains(e.target) && !props.disabled; show.value = (datepicker.value as any).contains(e.target) && !props.disabled;
}; };
const quickPick = (type: string) => { const quickPick = (type: string) => {

View File

@ -23,7 +23,7 @@ import Radio from "./Radio.vue";
import SelectSingle from "./SelectSingle.vue"; import SelectSingle from "./SelectSingle.vue";
import VueGridLayout from "vue-grid-layout"; import VueGridLayout from "vue-grid-layout";
const components: { [key: string]: any } = { const components: Indexable = {
Icon, Icon,
TimePicker, TimePicker,
VueGridLayout, VueGridLayout,

View File

@ -67,7 +67,7 @@ screenMap.set(sizeEnum.LG, screenEnum.LG);
screenMap.set(sizeEnum.XL, screenEnum.XL); screenMap.set(sizeEnum.XL, screenEnum.XL);
screenMap.set(sizeEnum.XXL, screenEnum.XXL); screenMap.set(sizeEnum.XXL, screenEnum.XXL);
export const RespFields: any = { export const RespFields: Indexable = {
readMetricsValues: `{ readMetricsValues: `{
label label
values { values {

View File

@ -19,7 +19,7 @@ import dateFormatStep from "@/utils/dateFormat";
import getLocalTime from "@/utils/localtime"; import getLocalTime from "@/utils/localtime";
import type { EventParams } from "@/types/app"; import type { EventParams } from "@/types/app";
export default function associateProcessor(props: any) { export default function associateProcessor(props: Indexable) {
function eventAssociate() { function eventAssociate() {
if (!props.filters) { if (!props.filters) {
return; return;
@ -85,7 +85,7 @@ export default function associateProcessor(props: any) {
const queryOrder = relatedTrace.queryOrder; const queryOrder = relatedTrace.queryOrder;
const latency = relatedTrace.latency; const latency = relatedTrace.latency;
const series = props.option.series || []; const series = props.option.series || [];
const item: any = { const item: Indexable = {
duration, duration,
queryOrder, queryOrder,
status, status,

View File

@ -32,7 +32,7 @@ export interface CreateCallbackParams {
sizeEnum: typeof sizeEnum; sizeEnum: typeof sizeEnum;
} }
export function useBreakpoint(): any { export function useBreakpoint(): Indexable {
return { return {
screenRef: computed(() => unref(globalScreenRef)), screenRef: computed(() => unref(globalScreenRef)),
widthRef: globalWidthRef, widthRef: globalWidthRef,
@ -41,7 +41,7 @@ export function useBreakpoint(): any {
}; };
} }
export function createBreakpointListen(fn?: (opt: CreateCallbackParams) => void): any { export function createBreakpointListen(fn?: (opt: CreateCallbackParams) => void): Indexable {
const screenRef = ref<sizeEnum>(sizeEnum.XL || ""); const screenRef = ref<sizeEnum>(sizeEnum.XL || "");
const realWidthRef = ref(window.innerWidth); const realWidthRef = ref(window.innerWidth);

View File

@ -59,7 +59,7 @@ export default function getDashboard(param?: { name: string; layer: string; enti
if (targetTabIndex[1] === undefined) { if (targetTabIndex[1] === undefined) {
container = document.querySelector(".ds-main"); container = document.querySelector(".ds-main");
} else { } else {
const w = widgets.find((d: any) => d.id === targetTabIndex[0]); const w = widgets.find((d: Indexable) => d.id === targetTabIndex[0]);
container = document.querySelector(".tab-layout"); container = document.querySelector(".tab-layout");
const layout: Nullable<Element> = document.querySelector(".ds-main"); const layout: Nullable<Element> = document.querySelector(".ds-main");
if (w && layout) { if (w && layout) {

View File

@ -43,7 +43,7 @@ export type ECOption = echarts.ComposeOption<
| SankeySeriesOption | SankeySeriesOption
>; >;
export function useECharts(elRef: Ref<HTMLDivElement>, theme: "light" | "dark" | "default" = "default"): any { export function useECharts(elRef: Ref<HTMLDivElement>, theme: "light" | "dark" | "default" = "default"): Indexable {
const getDarkMode = computed(() => { const getDarkMode = computed(() => {
return theme === "default" ? "light" : theme; return theme === "default" ? "light" : theme;
}); });

View File

@ -20,7 +20,7 @@ import { useThrottleFn, useDebounceFn } from "@vueuse/core";
export type RemoveEventFn = () => void; export type RemoveEventFn = () => void;
export interface UseEventParams { export interface UseEventParams {
el?: Element | Ref<Element | undefined> | Window | any; el?: Element | Ref<Element | undefined> | Window | Recordable;
name: string; name: string;
listener: EventListener; listener: EventListener;
options?: boolean | AddEventListenerOptions; options?: boolean | AddEventListenerOptions;

View File

@ -39,7 +39,7 @@ export default function useLegendProcess(legend?: LegendOptions) {
} }
function aggregations(data: { [key: string]: number[] }, intervalTime: string[]) { function aggregations(data: { [key: string]: number[] }, intervalTime: string[]) {
const source: { [key: string]: unknown }[] = []; const source: { [key: string]: unknown }[] = [];
const keys = Object.keys(data || {}).filter((i: any) => Array.isArray(data[i]) && data[i].length); const keys = Object.keys(data || {}).filter((i: string) => Array.isArray(data[i]) && data[i].length);
const headers = []; const headers = [];
for (const [key, value] of keys.entries()) { for (const [key, value] of keys.entries()) {

View File

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { MetricQueryTypes, Calculations } from "./data"; import { MetricQueryTypes, Calculations } from "./data";
export function useListConfig(config: any, index: string) { export function useListConfig(config: Indexable, index: string) {
const i = Number(index); const i = Number(index);
const types = [Calculations.Average, Calculations.ApdexAvg, Calculations.PercentageAvg]; const types = [Calculations.Average, Calculations.ApdexAvg, Calculations.PercentageAvg];
const calculation = config.metricConfig && config.metricConfig[i] && config.metricConfig[i].calculation; const calculation = config.metricConfig && config.metricConfig[i] && config.metricConfig[i].calculation;

View File

@ -24,7 +24,7 @@ import type { Instance, Endpoint, Service } from "@/types/selector";
import type { MetricConfigOpt } from "@/types/dashboard"; import type { MetricConfigOpt } from "@/types/dashboard";
import { MetricCatalog } from "@/views/dashboard/data"; import { MetricCatalog } from "@/views/dashboard/data";
export function useQueryProcessor(config: any) { export function useQueryProcessor(config: Indexable) {
if (!(config.metrics && config.metrics[0])) { if (!(config.metrics && config.metrics[0])) {
return; return;
} }
@ -126,7 +126,7 @@ export function useQueryProcessor(config: any) {
}; };
} }
export function useSourceProcessor( export function useSourceProcessor(
resp: { errors: string; data: { [key: string]: any } }, resp: { errors: string; data: Indexable },
config: { config: {
metrics: string[]; metrics: string[];
metricTypes: string[]; metricTypes: string[];
@ -181,7 +181,7 @@ export function useSourceProcessor(
} }
if (type === MetricQueryTypes.READHEATMAP) { if (type === MetricQueryTypes.READHEATMAP) {
const resVal = Object.values(resp.data)[0] || {}; const resVal = Object.values(resp.data)[0] || {};
const nodes = [] as any; const nodes = [] as Indexable[];
if (!(resVal && resVal.values)) { if (!(resVal && resVal.values)) {
source[m] = { nodes: [] }; source[m] = { nodes: [] };
return; return;
@ -191,7 +191,7 @@ export function useSourceProcessor(
nodes.push(...grids); nodes.push(...grids);
}); });
let buckets = [] as any; let buckets = [] as Indexable[];
if (resVal.buckets.length) { if (resVal.buckets.length) {
buckets = [resVal.buckets[0].min, ...resVal.buckets.map((item: { min: string; max: string }) => item.max)]; buckets = [resVal.buckets[0].min, ...resVal.buckets.map((item: { min: string; max: string }) => item.max)];
} }
@ -204,7 +204,7 @@ export function useSourceProcessor(
} }
export function useQueryPodsMetrics( export function useQueryPodsMetrics(
pods: Array<Instance | Endpoint | Service | any>, pods: Array<(Instance | Endpoint | Service) & Indexable>,
config: { config: {
metrics: string[]; metrics: string[];
metricTypes: string[]; metricTypes: string[];
@ -227,7 +227,7 @@ export function useQueryPodsMetrics(
}; };
const variables: string[] = [`$duration: Duration!`]; const variables: string[] = [`$duration: Duration!`];
const currentService = selectorStore.currentService || {}; const currentService = selectorStore.currentService || {};
const fragmentList = pods.map((d: (Instance | Endpoint | Service) & { normal: boolean }, index: number) => { const fragmentList = pods.map((d: (Instance | Endpoint | Service) & Indexable, index: number) => {
const param = { const param = {
scope, scope,
serviceName: scope === "Service" ? d.label : currentService.label, serviceName: scope === "Service" ? d.label : currentService.label,
@ -262,13 +262,13 @@ export function useQueryPodsMetrics(
export function usePodsSource( export function usePodsSource(
pods: Array<Instance | Endpoint>, pods: Array<Instance | Endpoint>,
resp: { errors: string; data: { [key: string]: any } }, resp: { errors: string; data: Indexable },
config: { config: {
metrics: string[]; metrics: string[];
metricTypes: string[]; metricTypes: string[];
metricConfig: MetricConfigOpt[]; metricConfig: MetricConfigOpt[];
}, },
): any { ): Indexable {
if (resp.errors) { if (resp.errors) {
ElMessage.error(resp.errors); ElMessage.error(resp.errors);
return {}; return {};
@ -276,7 +276,7 @@ export function usePodsSource(
const names: string[] = []; const names: string[] = [];
const metricConfigArr: MetricConfigOpt[] = []; const metricConfigArr: MetricConfigOpt[] = [];
const metricTypesArr: string[] = []; const metricTypesArr: string[] = [];
const data = pods.map((d: Instance | any, idx: number) => { const data = pods.map((d: Instance & Indexable, idx: number) => {
config.metrics.map((name: string, index: number) => { config.metrics.map((name: string, index: number) => {
const c: any = (config.metricConfig && config.metricConfig[index]) || {}; const c: any = (config.metricConfig && config.metricConfig[index]) || {};
const key = name + idx + index; const key = name + idx + index;
@ -424,7 +424,7 @@ export function aggregation(val: number, config: { calculation?: string }): numb
return data; return data;
} }
export async function useGetMetricEntity(metric: string, metricType: any) { export async function useGetMetricEntity(metric: string, metricType: MetricQueryTypes) {
if (!metric || !metricType) { if (!metric || !metricType) {
return; return;
} }
@ -441,7 +441,7 @@ export async function useGetMetricEntity(metric: string, metricType: any) {
return; return;
} }
const c: string = res.data.metrics[0].catalog; const c: string = res.data.metrics[0].catalog;
catalog = (MetricCatalog as any)[c]; catalog = (MetricCatalog as Indexable)[c];
} }
return catalog; return catalog;

View File

@ -47,6 +47,7 @@ limitations under the License. -->
import { useAppStoreWithOut } from "@/store/modules/app"; import { useAppStoreWithOut } from "@/store/modules/app";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
/*global Indexable */
const { t } = useI18n(); const { t } = useI18n();
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
const route = useRoute(); const route = useRoute();
@ -65,7 +66,7 @@ limitations under the License. -->
appStore.setDuration(timeFormat(dates)); appStore.setDuration(timeFormat(dates));
} }
function changeTimeRange(val: Date[] | any) { function changeTimeRange(val: Date[]) {
timeRange.value = val[1].getTime() - val[0].getTime() > 60 * 24 * 60 * 60 * 1000 ? 1 : 0; timeRange.value = val[1].getTime() - val[0].getTime() > 60 * 24 * 60 * 60 * 1000 ? 1 : 0;
if (timeRange.value) { if (timeRange.value) {
return; return;
@ -86,7 +87,7 @@ limitations under the License. -->
} }
} }
function resetDuration() { function resetDuration() {
const { duration }: any = route.params; const { duration }: Indexable = route.params;
if (duration) { if (duration) {
const d = JSON.parse(duration); const d = JSON.parse(duration);

View File

@ -49,7 +49,9 @@ declare global {
declare type Nullable<T> = T | null; declare type Nullable<T> = T | null;
declare type NonNullable<T> = T extends null | undefined ? never : T; declare type NonNullable<T> = T extends null | undefined ? never : T;
// String type object
declare type Recordable<T = any> = Record<string, T>; declare type Recordable<T = any> = Record<string, T>;
// Object of read-only string type
declare type ReadonlyRecordable<T = any> = { declare type ReadonlyRecordable<T = any> = {
readonly [key: string]: T; readonly [key: string]: T;
}; };
@ -108,6 +110,11 @@ declare global {
} }
} }
} }
type AnyNormalFunction = (...arg: any) => any;
type AnyPromiseFunction = (...arg: any) => PromiseLike<any>;
type AnyFunction = AnyNormalFunction | AnyPromiseFunction;
declare module "vue" { declare module "vue" {
export type JSXComponent<Props = any> = { new (): ComponentPublicInstance<Props> } | FunctionalComponent<Props>; export type JSXComponent<Props = any> = { new (): ComponentPublicInstance<Props> } | FunctionalComponent<Props>;