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
I recently stumbled across a method of inferring the type of the return value depending on the value of the argument.
The use-case for me was creating an API that would, given a path to a resource, automatically return the correct type for that specific resource.
Here is an example demonstrating intended functionality:
interfaceSomeType{a: number;}interfaceOtherType{b: number;}// In this case, both a and a2 will be of type SomeTypeconsta=pathFetch(pathMap.someResource);consta2=pathFetch("/v1/some_resource");// In this case, b will be of type OtherTypeconstb=pathFetch(pathMap.otherType);
The text was updated successfully, but these errors were encountered:
I recently stumbled across a method of inferring the type of the return value depending on the value of the argument.
The use-case for me was creating an API that would, given a path to a resource, automatically return the correct type for that specific resource.
Here is an example demonstrating intended functionality:
The text was updated successfully, but these errors were encountered: