Skip to content

Commit a236229

Browse files
committed
feat(typing): add declaration type
1 parent c1aa16d commit a236229

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

packages/mock-addon/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"main": "dist/cjs/index.js",
2424
"module": "dist/esm/index.js",
25-
"types": "dist/ts/index.d.ts",
25+
"types": "typings.d.ts",
2626
"files": [
2727
"dist/**/*",
2828
"README.md",

packages/mock-addon/src/typings.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/mock-addon/typings.d.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
type JSONValue = string | number | boolean | JSONObject | JSONArray
2+
type JSONArray = Array<JSONValue>
3+
interface JSONObject {
4+
[x: string]: JSONValue
5+
}
6+
7+
export type Method = 'GET' | 'PUT' | 'POST' | 'DELETE' | 'PATCH' | 'OPTIONS'
8+
9+
export type Request = {
10+
body: string | null
11+
method: Method
12+
signal: AbortSignal | null
13+
url: string
14+
searchParams?: string
15+
}
16+
17+
export type ResponseObj = JSONObject | JSONArray
18+
export type ResponseFn = (request: Request) => JSONValue
19+
export type Response = ResponseObj | ResponseFn
20+
21+
export type StorybookAddonMockData = {
22+
url: string
23+
/** @default GET */
24+
method: Method
25+
/** @default 0 */
26+
delay?: number
27+
status: number
28+
response: Response
29+
}
30+
31+
declare module '@storybook/csf' {
32+
interface Parameters {
33+
mockAddonConfigs?: {
34+
globalMockData?: StorybookAddonMockData[]
35+
ignoreQueryParams?: boolean
36+
refreshStoryOnUpdate?: boolean
37+
disableUsingOriginal?: boolean
38+
disable?: boolean
39+
}
40+
mockData?: StorybookAddonMockData[]
41+
}
42+
}

0 commit comments

Comments
 (0)