Skip to content

Commit 8932721

Browse files
committed
refactor: stricter TS types, tsconfig cleanup
1 parent 6648fd4 commit 8932721

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

src/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,21 @@ export class HTTPSnippet {
140140
): Request & {
141141
allHeaders: Record<string, string[] | string>;
142142
fullUrl: string;
143-
url: any;
144-
uriObj: any;
143+
url: string;
144+
uriObj: {
145+
query: ReducedHelperObject;
146+
search: string;
147+
path: string | null;
148+
auth: string | null;
149+
hash: string | null;
150+
host: string | null;
151+
hostname: string | null;
152+
href: string;
153+
pathname: string | null;
154+
protocol: string | null;
155+
slashes: boolean | null;
156+
port: string | null;
157+
};
145158
} {
146159
const request: Request = {
147160
...harRequest,

src/targets/php/helpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { escapeString } from '../../helpers/escape.js';
22

3-
export const convertType = (obj: any[] | any, indent?: string, lastIndent?: string): unknown => {
3+
export const convertType = (obj: any[] | any, indent?: string, lastIndent?: string): 'null' | string => {
44
lastIndent = lastIndent || '';
55
indent = indent || '';
66

@@ -41,7 +41,7 @@ export const convertType = (obj: any[] | any, indent?: string, lastIndent?: stri
4141
}
4242
};
4343

44-
export const supportedMethods: string[] = [
44+
export const supportedMethods = [
4545
'ACL',
4646
'BASELINE_CONTROL',
4747
'CHECKIN',
@@ -69,4 +69,4 @@ export const supportedMethods: string[] = [
6969
'UNLOCK',
7070
'UPDATE',
7171
'VERSION_CONTROL',
72-
];
72+
] as const;

src/targets/php/http1/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ export const http1: Client<Http1Options> = {
3636
blank();
3737
}
3838

39-
if (!supportedMethods.includes(method.toUpperCase())) {
39+
if (!supportedMethods.includes(method.toUpperCase() as (typeof supportedMethods)[number])) {
4040
push(`HttpRequest::methodRegister('${method}');`);
4141
}
4242

4343
push('$request = new HttpRequest();');
4444
push(`$request->setUrl(${convertType(url)});`);
4545

46-
if (supportedMethods.includes(method.toUpperCase())) {
46+
if (supportedMethods.includes(method.toUpperCase() as (typeof supportedMethods)[number])) {
4747
push(`$request->setMethod(HTTP_METH_${method.toUpperCase()});`);
4848
} else {
4949
push(`$request->setMethod(HttpRequest::HTTP_METH_${method.toUpperCase()});`);

tsconfig.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"compilerOptions": {
33
"declaration": true,
4-
"downlevelIteration": true,
54
"esModuleInterop": true,
65
"isolatedDeclarations": true,
76
"lib": ["DOM", "ES2020"],
@@ -10,13 +9,12 @@
109
"noEmit": true,
1110
"outDir": "dist",
1211
"resolveJsonModule": true,
12+
"strict": true,
1313
"target": "ES2020",
14-
1514
// Allows us to not have to typeguard in catches.
1615
// https://bobbyhadz.com/blog/typescript-object-is-of-type-unknown
1716
"useUnknownInCatchVariables": false,
18-
19-
"strict": true
17+
"verbatimModuleSyntax": true
2018
},
2119
"exclude": ["dist/", "./src/fixtures/", "**/*.test.ts"],
2220
"include": ["./src/**/*"]

0 commit comments

Comments
 (0)