Skip to content

Instantly share code, notes, and snippets.

@minenwerfer
Created December 27, 2024 04:01
Show Gist options
  • Save minenwerfer/3f355b7e5f3c32514244ce64ffbe2724 to your computer and use it in GitHub Desktop.
Save minenwerfer/3f355b7e5f3c32514244ce64ffbe2724 to your computer and use it in GitHub Desktop.
type FromInput<T, Acc = never> = T extends `${string}{${infer K}}${infer Rest}`
? FromInput<Rest, Acc | K>
: Acc
declare const t: <const TInput>(input: TInput, options: {
replace: Record<FromInput<TInput>, unknown>
}) => string
enum Messages {
InitialMessage = 'hello, {name}! you have {n} messages',
}
t(Messages.InitialMessage, {
replace: {
name: 'User',
n: 0,
},
})
t(Messages.InitialMessage, {
replace: {
// @ts-expect-error the line below will fail as 'nxame' does not exist on 'name' | 'n'
nxame: 'User',
n: 0,
},
})
export {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment