Skip to content

feat(typing): add declaration type #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/mock-addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion packages/mock-addon/src/typings.d.ts

This file was deleted.

41 changes: 41 additions & 0 deletions packages/mock-addon/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
type JSONValue = string | number | boolean | JSONObject | JSONArray
type JSONArray = Array<JSONValue>
interface JSONObject {
[x: string]: JSONValue
}

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 = JSONObject | JSONArray
export type ResponseFn = (request: Request) => JSONValue
export type Response = ResponseObj | ResponseFn

export type StorybookAddonMockData = {
url: string
method: Method
/** @default 0 */
delay?: number
status: number
response: Response
}

declare module '@storybook/csf' {
interface Parameters {
mockAddonConfigs?: {
globalMockData?: StorybookAddonMockData[]
ignoreQueryParams?: boolean
refreshStoryOnUpdate?: boolean
disableUsingOriginal?: boolean
disable?: boolean
}
mockData?: StorybookAddonMockData[]
}
}