Skip to content

Commit

Permalink
common: Enable TypeScript strict for packages/auth-fetch (#1493)
Browse files Browse the repository at this point in the history
* Add tsconfig strict to packages/auth-fetch

* Refactor switch case

* Revert "Refactor switch case"

This reverts commit b500466.

* Revert switch changes
  • Loading branch information
longzheng committed Jun 4, 2024
1 parent 9a770e9 commit cf1c500
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/auth-fetch/src/auth-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function getAuth(options: AuthFetchOptions, url: string | URL, method: str

export function createAuthFetch<B, M>(
h: fetcher<B, M>,
parser: (body: M, responseType: HttpFetchResponseType) => Promise<any>
parser: (body: M, responseType: HttpFetchResponseType | undefined) => Promise<any>
) {
const authHttpFetch = async <T extends HttpFetchOptions<B>>(options: T & AuthFetchOptions): ReturnType<typeof h<T>> => {
const method = getFetchMethod(options);
Expand Down Expand Up @@ -99,7 +99,7 @@ export function createAuthFetch<B, M>(
};
}

let authenticateHeaders: string | string[] = initialResponse.headers.get('www-authenticate');
let authenticateHeaders: string | string[] | null = initialResponse.headers.get('www-authenticate');
if (!authenticateHeaders)
throw new Error('Did not find WWW-Authenticate header.');

Expand Down
1 change: 1 addition & 0 deletions packages/auth-fetch/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"inlineSources": true,
"declaration": true,
"resolveJsonModule": true,
"strict": true
},
"include": [
"src/**/*"
Expand Down
4 changes: 2 additions & 2 deletions server/src/fetch/http-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const StreamParser: FetchParser<IncomingMessage> = {
}
}

export function getHttpFetchParser(responseType: HttpFetchResponseType) {
export function getHttpFetchParser(responseType: HttpFetchResponseType | undefined) {
switch (responseType) {
case 'json':
return JSONParser;
Expand All @@ -53,7 +53,7 @@ export function getHttpFetchParser(responseType: HttpFetchResponseType) {
return BufferParser;
}

export function httpFetchParseIncomingMessage(readable: IncomingMessage, responseType: HttpFetchResponseType) {
export function httpFetchParseIncomingMessage(readable: IncomingMessage, responseType: HttpFetchResponseType | undefined) {
return getHttpFetchParser(responseType).parse(readable);
}

Expand Down
8 changes: 4 additions & 4 deletions server/src/fetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export type fetcher<B, M> = <T extends HttpFetchOptions<B>>(options: T) => Promi
>>;


export function getHttpFetchAccept(responseType: HttpFetchResponseType) {
export function getHttpFetchAccept(responseType: HttpFetchResponseType | undefined) {
switch (responseType) {
case 'json':
return 'application/json';
Expand All @@ -89,15 +89,15 @@ export function setHeader(headers: [string, string][], key: string, value: strin
headers.push([key, value]);
}

export function setDefaultHttpFetchAccept(headers: [string, string][], responseType: HttpFetchResponseType) {
export function setDefaultHttpFetchAccept(headers: [string, string][], responseType: HttpFetchResponseType | undefined) {
if (hasHeader(headers, 'Accept'))
return;
const accept = getHttpFetchAccept(responseType);
if (accept)
setHeader(headers, 'Accept', accept);
}

export function createHeadersArray(headers: HeadersInit): [string, string][] {
export function createHeadersArray(headers: HeadersInit | undefined): [string, string][] {
const headersArray: [string, string][] = [];
if (!headers)
return headersArray;
Expand Down Expand Up @@ -144,7 +144,7 @@ export function createStringOrBufferBody(headers: [string, string][], body: any)
return body;
}

export async function domFetchParseIncomingMessage(response: Response, responseType: HttpFetchResponseType) {
export async function domFetchParseIncomingMessage(response: Response, responseType: HttpFetchResponseType | undefined) {
switch (responseType) {
case 'json':
return response.json();
Expand Down

0 comments on commit cf1c500

Please sign in to comment.