Skip to content

Commit

Permalink
Update code to make it TS 4.4 compatible (#1319)
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch authored and srajiang committed Dec 10, 2021
1 parent 75be454 commit bf46c00
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/oauth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"dependencies": {
"@slack/logger": "^3.0.0",
"@slack/web-api": "^6.0.0",
"@slack/web-api": "^6.3.0",
"@types/jsonwebtoken": "^8.3.7",
"@types/node": ">=12",
"jsonwebtoken": "^8.5.1",
Expand All @@ -64,4 +64,4 @@
"typescript": "^4.1",
"uncaughtException": "^1.0.0"
}
}
}
4 changes: 2 additions & 2 deletions packages/oauth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class InstallProvider {
}

return authResult;
} catch (error) {
} catch (error: any) {
throw new AuthorizationError(error.message);
}
}
Expand Down Expand Up @@ -453,7 +453,7 @@ export class InstallProvider {
this.logger.debug('run built-in success function');
callbackSuccess(installation, installOptions, req, res);
}
} catch (error) {
} catch (error: any) {
this.logger.error(error);

// Call the failure callback
Expand Down
2 changes: 1 addition & 1 deletion packages/rtm-api/src/KeepAlive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export class KeepAlive extends EventEmitter {
.catch((error) => {
this.logger.error(`Unhandled error: ${error.message}. Please report to @slack/rtm-api package maintainers.`);
});
} catch (error) {
} catch (error: any) {
this.logger.error(`Unhandled error: ${error.message}. Please report to @slack/rtm-api package maintainers.`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rtm-api/src/RTMClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ export class RTMClient extends EventEmitter {
let event;
try {
event = JSON.parse(data);
} catch (parseError) {
} catch (parseError: any) {
// prevent application from crashing on a bad message, but log an error to bring attention
this.logger.error(
`unable to parse incoming websocket message: ${parseError.message}\n message contents: "${data}"`,
Expand Down
2 changes: 1 addition & 1 deletion packages/socket-mode/src/SocketModeClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ export class SocketModeClient extends EventEmitter {

try {
event = JSON.parse(data);
} catch (parseError) {
} catch (parseError: any) {
// prevent application from crashing on a bad message, but log an error to bring attention
this.logger.error(
`unable to parse incoming websocket message: ${parseError.message}`,
Expand Down
10 changes: 6 additions & 4 deletions packages/web-api/src/WebClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,11 @@ export class WebClient extends Methods {

return response;
} catch (error) {
this.logger.warn('http request failed', error.message);
if (error.request) {
throw requestErrorWithOriginal(error);
// To make this compatible with tsd, casting here instead of `catch (error: any)`
const e = error as any;
this.logger.warn('http request failed', e.message);
if (e.request) {
throw requestErrorWithOriginal(e);
}
throw error;
}
Expand Down Expand Up @@ -571,7 +573,7 @@ function paginationOptionsForNextPage(
cursor: previousResult.response_metadata.next_cursor as string,
};
}
return;
return undefined;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ expectError(web.paginate('conversations.list', {}, () => 7));

expectType<Promise<number>>(web.paginate('conversations.list', {}, () => false, () => 5));

// NOTE: this error does not arise with TypeScript 4.4+
// When there's no shouldStop predicate given but there is a reducer, the behavior is undefined.
// (However in the current implementation, the return value is `AsyncIteratable<WebAPICallResult>`.)
expectError(web.paginate('conversations.list', {}, undefined, () => 5));
// expectError(web.paginate('conversations.list', {}, undefined, () => 5));

// Ensure that it works in a for-await-of loop.
async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/webhook/src/IncomingWebhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class IncomingWebhook {
try {
const response = await this.axios.post(this.url, payload);
return this.buildResult(response);
} catch (error) {
} catch (error: any) {
// Wrap errors in this packages own error types (abstract the implementation details' types)
if (error.response !== undefined) {
throw httpErrorWithOriginal(error);
Expand Down

0 comments on commit bf46c00

Please sign in to comment.