TITO
TITO
WWindmill
Created by TITO on 11/28/2024 in #help
Unexpected Const Error
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);
}
}

...
};
3 replies