Skip to content

Commit a5b3faa

Browse files
refactor: refactor types
1 parent ec10f8a commit a5b3faa

File tree

9 files changed

+40
-42
lines changed

9 files changed

+40
-42
lines changed

package-lock.json

Lines changed: 0 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,6 @@
146146
"@testing-library/jest-dom": "^6.6.3",
147147
"@testing-library/react": "^16.3.0",
148148
"@testing-library/user-event": "^14.6.1",
149-
"@types/lodash": "^4.17.17",
150-
"@types/swagger-ui-react": "^5.18.0",
151149
"@typescript-eslint/eslint-plugin": "^5.62.0",
152150
"@typescript-eslint/parser": "^5.62.0",
153151
"copyfiles": "^2.4.1",

src/plugins/props-change-watcher/actions.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
import { Action } from 'types/actions';
2+
13
export const EDITOR_PROP_CHANGED = 'EDITOR_PROP_CHANGED';
24

3-
export const propChanged = (propName: string, newValue: unknown, oldValue: unknown) => ({
5+
export type PropChangedAction = (
6+
propName: string,
7+
newValue: unknown,
8+
oldValue: unknown
9+
) => Action<string, { newValue: unknown; oldValue: unknown }>;
10+
11+
export const propChanged: PropChangedAction = (propName, newValue, oldValue) => ({
412
type: EDITOR_PROP_CHANGED,
513
payload: propName,
614
meta: { newValue, oldValue },

src/plugins/props-change-watcher/hooks/use-mount-plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { useRef } from 'react';
2-
import { GetSystemValues, System } from 'types/system';
2+
import { SystemValues, System } from 'types/system';
33

44
import pluginImpl from '../plugin-impl';
55

66
const useMountPlugin = () => {
7-
const system = useRef<null | GetSystemValues>(null);
7+
const system = useRef<null | SystemValues>(null);
88

99
return {
1010
plugin(sys: System) {

src/plugins/props-change-watcher/hooks/use-prop-change.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useRef } from 'react';
22

33
type UsePropChangeCallback = (newValue: unknown, oldValue: unknown) => void;
44

5-
const usePropChange = (prop: string | object | undefined, callback: UsePropChangeCallback) => {
5+
const usePropChange = (prop: unknown, callback: UsePropChangeCallback) => {
66
const isInitialMount = useRef(true);
77
const previousProp = useRef(prop);
88

src/types/actions.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export type AnyAction<T extends string = string> = {
2+
type: T;
3+
};
4+
5+
export interface Action<
6+
Payload,
7+
Meta extends Record<string, unknown> | unknown[] | undefined = undefined,
8+
> extends AnyAction {
9+
type: string;
10+
payload: Payload;
11+
error?: boolean;
12+
meta?: Meta;
13+
}

src/types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ declare module 'swagger-ui-react' {
77
}
88
type System = unknown;
99

10-
type PluginGenerator = (system: System) => object;
10+
export type PluginGenerator = (system: System) => object;
1111

12-
type Plugin = object | PluginGenerator;
12+
export type Plugin = object | PluginGenerator;
1313

1414
export type Preset = () => unknown;
1515

src/types/swagger-editor.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import React from 'react';
2-
import { Preset, SwaggerUIProps } from 'swagger-ui-react';
3-
import { System } from 'types/system';
4-
5-
type PluginGenerator = (system: System) => object;
6-
7-
type Plugin = object | PluginGenerator;
2+
import { Preset, SwaggerUIProps, Plugin } from 'swagger-ui-react';
83

94
enum presetNames {
105
textarea = 'textarea',

src/types/system.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
export interface GetSystemValues {
1+
import { PropChangedAction } from 'plugins/props-change-watcher/actions';
2+
import { Action } from 'types/actions';
3+
4+
export interface SystemValues {
25
getComponent: () => void;
36
editorSelectors: {
4-
selectContent: () => unknown;
5-
selectInferFileNameWithExtensionFromContent: () => unknown;
7+
selectContent: () => string;
8+
selectInferFileNameWithExtensionFromContent: () => string;
69
};
710
editorActions: {
8-
convertContentToJSON: () => void;
9-
setContent: (content: unknown) => void;
10-
propChanged: (spec: string, oldValue: unknown, newValue: unknown) => void;
11+
convertContentToJSON: (content: string) => Action<string>;
12+
setContent: (content: string) => Action<string>;
13+
propChanged: PropChangedAction;
1114
};
1215
EditorContentOrigin: {
13-
Conversion: string;
16+
Conversion: 'conversion';
1417
};
1518
}
1619

17-
export interface System {
18-
getSystem: () => GetSystemValues;
20+
export interface System extends SystemValues {
21+
getSystem: () => SystemValues;
1922
}

0 commit comments

Comments
 (0)