79119341

Date: 2024-10-23 18:59:19
Score: 0.5
Natty:
Report link

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.

Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Awaterujin