I don't think Typescript has a later binding of generic types.
But if this particular code was in the context of a function, you could use generics to achieve a similar thing.
function example<T>(val:T){ let a : T[] return [val] } let a = example(4) // number[] :: [4] let b = example('hello') // string[] :: ['hello']
Here is an interactive example: link
Try hovering over a or b to see it in action.
source share