Typed ICU message arguments #3992
offirgolan
started this conversation in
Show and tell
Replies: 3 comments · 4 replies
-
This is pretty cool! Does this handle escaping properly? |
Beta Was this translation helpful? Give feedback.
4 replies
-
@offirgolan this is incredible work -- I'd love to see you continue to refine it and publish it as a package in some form. |
Beta Was this translation helpful? Give feedback.
0 replies
-
👋 Hi there, its taken me a while to come back to this but I ended up completely overhauling the original implementation and created a types-only NPM package (icu-message-types). import type { ICUMessageArguments, ICUMessageTags } from 'icu-message-types';
// Extract argument types
type Args0 = ICUMessageArguments<'Hello, {firstName} {lastName}!'>;
// Result: { firstName: string | number | boolean; lastName: string | number | boolean }
type Args1 = ICUMessageArguments<`{theme, select,
light {The interface will be bright}
dark {The interface will be dark}
other {The interface will use default colors}
}`>;
// Result: { theme: 'light' | 'dark' | ({} & string) | ({} & number) | boolean | null }
// Extract tag names
type Tags = ICUMessageTags<'Click <link>here</link> to continue'>;
// Result: 'link' Message Arguments
Additional Features
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
👋 Hi there,
I've been working on extracting argument types from an ICU-formatted message string and wanted to share it here. It would be great if this was supported by this package directly but if there is no interest, this can just exist as a reference if anyone else would like something like this in their projects.
Gist can be found here.
Beta Was this translation helpful? Give feedback.
All reactions