Skip to content

Commit 60405da

Browse files
committed
chore: remove type assertion in getWaiterConfig
1 parent adfefab commit 60405da

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

src/transforms/v2-to-v3/apis/getWaiterConfig.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@ import type { ObjectExpression, ObjectProperty, Property } from "jscodeshift";
22

33
import { OBJECT_PROPERTY_TYPE_LIST } from "../config";
44

5-
export const getWaiterConfig = (callArgument: unknown): ObjectExpression | undefined => {
6-
if ((callArgument as ObjectExpression).type !== "ObjectExpression") {
7-
return;
8-
}
9-
for (const property of (callArgument as ObjectExpression).properties) {
5+
export const getWaiterConfig = (originalConfig: ObjectExpression): ObjectExpression | undefined => {
6+
for (const property of originalConfig.properties) {
107
if (!OBJECT_PROPERTY_TYPE_LIST.includes(property.type)) {
118
continue;
129
}

src/transforms/v2-to-v3/apis/getWaiterConfigValue.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@ import type { ObjectExpression, ObjectProperty, Property } from "jscodeshift";
22

33
import { OBJECT_PROPERTY_TYPE_LIST } from "../config";
44

5-
export const getWaiterConfigValue = (
6-
waiterConfiguration: ObjectExpression | undefined,
7-
key: string
8-
): string | undefined => {
9-
if (!waiterConfiguration) {
10-
return;
11-
}
5+
export const getWaiterConfigValue = (waiterConfiguration: ObjectExpression, key: string) => {
126
for (const property of waiterConfiguration.properties) {
137
if (!OBJECT_PROPERTY_TYPE_LIST.includes(property.type)) {
148
continue;
@@ -19,8 +13,15 @@ export const getWaiterConfigValue = (
1913
continue;
2014
}
2115
if (propertyKey.name === key) {
22-
// @ts-expect-error value is Literal/StringLiteral
23-
return propertyValue.value;
16+
if (propertyValue.type === "Literal" || propertyValue.type === "StringLiteral") {
17+
if (typeof propertyValue.value === "number") {
18+
return propertyValue.value.toString();
19+
}
20+
if (typeof propertyValue.value === "string") {
21+
return propertyValue.value;
22+
}
23+
}
24+
return;
2425
}
2526
}
2627
};

src/transforms/v2-to-v3/apis/replaceWaiterApi.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,17 @@ export const replaceWaiterApi = (
2121
source
2222
.find(j.CallExpression, getClientWaiterCallExpression(clientId, waiterState))
2323
.replaceWith((callExpression) => {
24-
const waiterConfig = getWaiterConfig(callExpression.node.arguments[1]);
25-
const delay = getWaiterConfigValue(waiterConfig, "delay");
26-
const maxAttempts = getWaiterConfigValue(waiterConfig, "maxAttempts");
24+
let delay: string | undefined;
25+
let maxAttempts: string | undefined;
26+
27+
const callArguments = callExpression.node.arguments;
28+
if (callArguments.length > 1 && callArguments[0].type === "ObjectExpression") {
29+
const waiterConfig = getWaiterConfig(callArguments[0]);
30+
if (waiterConfig) {
31+
delay = getWaiterConfigValue(waiterConfig, "delay");
32+
maxAttempts = getWaiterConfigValue(waiterConfig, "maxAttempts");
33+
}
34+
}
2735

2836
const properties = [];
2937
properties.push(

0 commit comments

Comments
 (0)