Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions packages/decap-cms-core/src/lib/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,20 +308,28 @@
if (structure === I18N_STRUCTURE.SINGLE_FILE) {
entryValue = mergeSingleFileValue(await getEntryValue(path), defaultLocale, locales);
} else {
const entryValues = await Promise.all(
const entryValuesResults = await Promise.allSettled(
locales.map(async locale => {
const entryPath = getFilePath(structure, extension, path, slug, locale);
const value = await getEntryValue(entryPath).catch(() => null);
const value = await getEntryValue(entryPath);
return { value, locale };
}),
);

const nonNullValues = entryValues.filter(e => e.value !== null) as {
value: EntryValue;
locale: string;
}[];
const nonNullValues = entryValuesResults
.map(e => (e.status === 'fulfilled' ? e.value : undefined))
.filter(e => e !== undefined);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the current version of TypeScript here doesn't infer the filter removing undefined from the possible values. I think the easier fix is to just bring back the type predicate.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.filter(e => e !== undefined);
.filter((e): e is { value: EntryValue; locale: string } => e !== undefined);


if (nonNullValues.length === 0) {
// mergeValues will throw on an empty list, and show the error messages.
const [error = new Error('No entry values found for any locale')] = entryValuesResults
.map(e => (e.status === 'rejected' ? e.reason : undefined))
.filter(e => e !== undefined);

throw error;
}

entryValue = mergeValues(collection, structure, defaultLocale, nonNullValues);

Check failure on line 332 in packages/decap-cms-core/src/lib/i18n.ts

View workflow job for this annotation

GitHub Actions / build-unit (macos-latest, 24.x)

Argument of type '({ value: EntryValue; locale: string; } | undefined)[]' is not assignable to parameter of type '{ locale: string; value: EntryValue; }[]'.
}

return entryValue;
Expand Down
Loading