const format = (str, ...vals) => vals.reduce((s, v, i) => s.replace(new RegExp('\\{' + i + '\\}', 'g'), v), str);
const format = (str: string, ...vals: unknown[]): string => vals.reduce((s, v, i) => s.replace(new RegExp('\\{' + i + '\\}', 'g'), v), str);
const template = 'My name is {0} and I am {1} years old';format(template, 'John', 30));// My name is John and I am 30 years oldformat(template, 'Jane', 20);// My name is Jane and I am 20 years old