Adding on from Alex Santos' answer, you can restrict the types that can be passed in; you can have T extend the types you want:
function foo<T extends string|number>(bar:T):T {
// ...transform bar...
return bar;
}
Now typescript will flag an error if you try passing in anything else.