edit
Due to course of time, this question has lost its validity, as it seems from the comments and answers to this one. Despite initial appearance, it\
Besides generics you can use function overloading
function getI18n(id: string[]): string[];
function getI18n(id: string): string;
function getI18n(id: string | string[]): string | string[] {
if (typeof id === 'string') {
return id + '_title';
}
return id.slice();
}
const title = getI18n('test'); // const title: string
const titles = getI18n(['a', 'b', 'c']); // const titles: string[]
Link to official docs on this feature: functions overloads