Type Transformations Workshop (9 exercises)

Functions as Constraints for Type Helpers

Consider this GetParametersAndReturnType type helper that is used to extract the parameters and return types of T:

There are a few test scenarios, all of which are passing:

Loading exercise


[0:00] For this exercise, we have a TypeHelper here called GetParametersAndReturnType. We have a bit of an issue. All the tests are parsing absolutely fine. We're taking our T here and we're extracting out the Parameters and ReturnType from this T. It's pretty much always going to be a function here.

[0:17] You have a function here, which is a function with no arguments that returns a string. This one is a function with one argument which is s, which is a string that returns void. We're getting returnValue: void and params: string there.

[0:30] In this one, you have two function arguments that returns a number here and the params get extracted to be a tuple of number and Boolean and returnValue.

[0:41] All appears to be working, except here, we have an error saying, "T does not satisfy a certain constraint." Your job here is to figure out what that constraint might be and you probably need to apply it somewhere to make sure that T is typed in a certain way.