To achieve a return using template literal type, you must return a template literal:
type Greetings = `Hello ${string}`
const name = 'World'
function greet(name: string): Greetings {
return `Hello ${name}`; // no errors
// return `Hola ${name}`; // error
// return `Hello${name}`; // error
}
Similarly, how can one return intrinsic string manipulation types?
type UppercaseFirstLetter = Capitalize<string>
function capitalizeFirstLetter(word: string): UppercaseFirstLetter {
return `${word.charAt(0).toUpperCase() + word.slice(1)}`
}
This approach does not produce the desired result.