The template string literal type (enables key inference).
The interpolated string.
// Named placeholder
interpolateString('Hello, {name}!', { name: 'Alice' });
// Returns "Hello, Alice!"
// Nested dot-notation path
interpolateString('Welcome, {user.profile.displayName}.', {
user: { profile: { displayName: 'Bob' } },
});
// Returns "Welcome, Bob."
// Positional (array) placeholders
interpolateString('{0} + {1} = {2}', [1, 2, 3]);
// Returns "1 + 2 = 3"
// Custom delimiters
interpolateString('Hello, {{name}}!' as string, { name: 'Carol' }, { open: '{{', close: '}}' });
// Returns "Hello, Carol!"
// Fallback for missing keys
interpolateString('Hi {firstName} {lastName}!', { firstName: 'Dave' }, { fallback: '?' });
// Returns "Hi Dave ?!"
// Fallback function
interpolateString('Hi {firstName} {lastName}!', { firstName: 'Eve' }, {
fallback: (key) => `<missing:${key}>`,
});
// Returns "Hi Eve <missing:lastName>!"
Interpolates a template string by replacing
{key}placeholders with values from a data object or array.Named placeholders resolve keys against a plain object, with support for dot-notation paths to access nested properties. Positional placeholders (
{0},{1}, …) resolve numeric indices against an array.