TITO
TITO4w ago

Unexpected Const Error

When running a typescript (bun) step I receive this error: 534 | const settled = results error: Unexpected const at input.tsx:534:3 Running it locally with bun run works fine. Only the deployed code errors out. Any ideas what could be causing this?
2 Replies
fr3fou
fr3fou4w ago
can you show the full code?
TITO
TITOOP2w ago
This is solved. Probably caused by a bun version update, but this code caused transpiling errors:
const separateResults = <T>(items: PromiseSettledResult<T>[]) => {
const successfulItems = items
.filter(
(item): item is PromiseFulfilledResult<T> => item.status === "successful"
)
.map((item) => item.value);

const failedItems = items.filter(
(item): item is PromiseRejectedResult => item.status === "failed"
);

...
};
const separateResults = <T>(items: PromiseSettledResult<T>[]) => {
const successfulItems = items
.filter(
(item): item is PromiseFulfilledResult<T> => item.status === "successful"
)
.map((item) => item.value);

const failedItems = items.filter(
(item): item is PromiseRejectedResult => item.status === "failed"
);

...
};
Removing type assertions fixed it
const separateResults = (items: PromiseSettledResult<unknown>[]) => {
const successfulItems: unknown[] = [];
const failedItems: unknown[] = [];

for (const item of items) {
if (item.status === "successful") {
successfulItems.push(item.value);
} else if (item.status === "failed") {
failedItems.push(item.reason);
}
}

...
};
const separateResults = (items: PromiseSettledResult<unknown>[]) => {
const successfulItems: unknown[] = [];
const failedItems: unknown[] = [];

for (const item of items) {
if (item.status === "successful") {
successfulItems.push(item.value);
} else if (item.status === "failed") {
failedItems.push(item.reason);
}
}

...
};

Did you find this page helpful?