From b274eaff02d53d09299ac09c61654232eca197eb Mon Sep 17 00:00:00 2001 From: PINGUET Julien Date: Mon, 11 Nov 2024 21:17:34 +0100 Subject: [PATCH] feat(typing): add declaration type --- packages/mock-addon/package.json | 2 +- packages/mock-addon/src/typings.d.ts | 1 - packages/mock-addon/typings.d.ts | 34 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) delete mode 100644 packages/mock-addon/src/typings.d.ts create mode 100644 packages/mock-addon/typings.d.ts diff --git a/packages/mock-addon/package.json b/packages/mock-addon/package.json index caa566b..e8ca0cb 100644 --- a/packages/mock-addon/package.json +++ b/packages/mock-addon/package.json @@ -22,7 +22,7 @@ }, "main": "dist/cjs/index.js", "module": "dist/esm/index.js", - "types": "dist/ts/index.d.ts", + "types": "typings.d.ts", "files": [ "dist/**/*", "README.md", diff --git a/packages/mock-addon/src/typings.d.ts b/packages/mock-addon/src/typings.d.ts deleted file mode 100644 index 0f79d45..0000000 --- a/packages/mock-addon/src/typings.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module "global"; \ No newline at end of file diff --git a/packages/mock-addon/typings.d.ts b/packages/mock-addon/typings.d.ts new file mode 100644 index 0000000..8167c0e --- /dev/null +++ b/packages/mock-addon/typings.d.ts @@ -0,0 +1,34 @@ +export type Method = 'GET' | 'PUT' | 'POST' | 'DELETE' | 'PATCH' | 'OPTIONS' + +export type Request = { + body: string | null + method: Method + signal: AbortSignal | null + url: string + searchParams?: string +} + +export type ResponseObj = string | object +export type ResponseFn = (request: Request) => ResponseObj +export type Response = ResponseObj | ResponseFn + +export type StorybookAddonMockData = { + url: string + method: Method + delay?: 0 | number + status: number + response: Response +} + +declare module '@storybook/csf' { + interface Parameters { + mockAddonConfigs?: { + globalMockData?: StorybookAddonMockData[] + ignoreQueryParams?: boolean + refreshStoryOnUpdate?: boolean + disableUsingOriginal?: boolean + disable?: boolean + } + mockData?: StorybookAddonMockData[] + } +}