Skip to content

Commit 36490d1

Browse files
committed
fix: add type declarations for fetch-error-handler
No need for tests for this module as it doesn't use default exports.
1 parent 8829b07 commit 36490d1

File tree

6 files changed

+30
-6
lines changed

6 files changed

+30
-6
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.husky/_
2-
packages/fetch-error-handler/**/*.d.*
32
packages/logger/**/*.d.*
43
coverage
54
node_modules/

jsconfig.build.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"removeComments": true
99
},
1010
"include": [
11-
"packages/fetch-error-handler/**/*.js",
1211
"packages/logger/**/*.js"
1312
]
1413
}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
!*.d.ts
2-
!*.d.ts.map
31
CHANGELOG.md
42
docs
53
test

packages/fetch-error-handler/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"node": "18.x || 20.x || 22.x",
1515
"npm": "8.x || 9.x || 10.x"
1616
},
17-
"main": "lib",
17+
"main": "lib/index.js",
18+
"types": "types/index.d.ts",
1819
"dependencies": {
1920
"@dotcom-reliability-kit/errors": "^3.1.1"
2021
},
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Writable } from 'stream';
2+
3+
declare module '@dotcom-reliability-kit/fetch-error-handler' {
4+
export type ErrorHandlerOptions = {
5+
upstreamSystemCode?: string;
6+
};
7+
8+
type NodeFetchResponseBody = {
9+
pipe?: (stream: Writable) => void;
10+
};
11+
12+
type FetchResponse = {
13+
ok: boolean;
14+
status: number;
15+
url: string;
16+
body: NodeFetchResponseBody | ReadableStream<Uint8Array> | null;
17+
};
18+
19+
export type FetchErrorHandler = <Response extends FetchResponse>(
20+
fetchPromise: Response | Promise<Response>
21+
) => Promise<Response>;
22+
23+
export function createFetchErrorHandler(
24+
options?: ErrorHandlerOptions
25+
): FetchErrorHandler;
26+
27+
export const handleFetchErrors: FetchErrorHandler;
28+
}

scripts/clean-generated-types.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
#!/usr/bin/env bash
22

3-
find ./packages/fetch-error-handler -name "*.d.ts*" | xargs -r rm
43
find ./packages/logger -name "*.d.ts*" | xargs -r rm

0 commit comments

Comments
 (0)