Skip to content

Commit

Permalink
Fix problem anonymous scopes unrecognized by Storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Sep 7, 2024
1 parent 0668aae commit 09a4cfa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
1 change: 1 addition & 0 deletions web/src/ui/i18n/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable react-refresh/only-export-components */
export * from "./i18n";

export { languages, fallbackLanguage, type Language } from "./types";
Expand Down
57 changes: 30 additions & 27 deletions web/src/ui/i18n/z.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { z } from "zod";
import { assert, type Equals } from "tsafe/assert";
import type { Language } from "core";
import type { LocalizedString } from "./i18n";
import { id } from "tsafe/id";

//List the languages you with to support
export const languages = [
Expand All @@ -18,30 +19,32 @@ export const languages = [

assert<Equals<(typeof languages)[number], Language>>();

export const zLanguage = z.union([
z.literal("en"),
z.literal("fr"),
z.literal("zh-CN"),
z.literal("no"),
z.literal("fi"),
z.literal("nl"),
z.literal("it"),
z.literal("es"),
z.literal("de")
]);

{
type Got = ReturnType<(typeof zLanguage)["parse"]>;
type Expected = Language;

assert<Equals<Got, Expected>>();
}

export const zLocalizedString = z.union([z.string(), z.record(zLanguage, z.string())]);

{
type Got = ReturnType<(typeof zLocalizedString)["parse"]>;
type Expected = LocalizedString;

assert<Equals<Got, Expected>>();
}
export const zLanguage = (() => {
type TargetType = Language;

const zTargetType = z.union([
z.literal("en"),
z.literal("fr"),
z.literal("zh-CN"),
z.literal("no"),
z.literal("fi"),
z.literal("nl"),
z.literal("it"),
z.literal("es"),
z.literal("de")
]);

assert<Equals<z.infer<typeof zTargetType>, TargetType>>();

return id<z.ZodType<TargetType>>(zTargetType);
})();

export const zLocalizedString = (() => {
type TargetType = LocalizedString;

const zTargetType = z.union([z.string(), z.record(zLanguage, z.string())]);

assert<Equals<z.infer<typeof zTargetType>, TargetType>>();

return id<z.ZodType<TargetType>>(zTargetType);
})();

0 comments on commit 09a4cfa

Please sign in to comment.