You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does ts-belt provide a tool to widen literal types ?
I currently have the code below. The get function extracts a configuration value out of an object with the option to pass a default value. When a default value is passed, I want the get function to return the same type like the default parameter. Problem is that without the Widen<T> conditional type, get will return a literal type (eg 3000 instead of number or host instead of string) which will causes havoc in subsequent code.
However, I don't like the Widen<T> type definition at all and have been searching the web for alternatives. This repository seems to be the place to find this kind of utility. I could't find a Widen function in ts-toolbelt, can ts-toolbelt be used for what I'm trying to do ?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Does ts-belt provide a tool to widen literal types ?
I currently have the code below. The get function extracts a configuration value out of an object with the option to pass a default value. When a default value is passed, I want the
get
function to return the same type like the default parameter. Problem is that without theWiden<T>
conditional type,get
will return a literal type (eg3000
instead ofnumber
orhost
instead ofstring
) which will causes havoc in subsequent code.However, I don't like the
Widen<T>
type definition at all and have been searching the web for alternatives. This repository seems to be the place to find this kind of utility. I could't find aWiden
function ints-toolbelt
, can ts-toolbelt be used for what I'm trying to do ?Beta Was this translation helpful? Give feedback.
All reactions