Type Helpers 9 exercises
Problem

Optional Type Parameters in Type Helpers

This exercise begins with a similar setup to the last.

We've got CreateDataShape which takes in TData and TError as arguments:


type CreateDataShape<TData, TError> = {
data: TData;
error: TError;
};

In the first test we're passing a string for data, and undefined for `erro

Loading exercise

Transcript

0:01 We've got a similar setup to what we had last time, which is our CreateDataShape, we've got our TData, and a TError. Except here, we've now only got two tests. The two tests are, we've got a CreateDataShape here, and we're passing in a string for data. We want error to be undefined here, except the error it's giving us is that generic-type CreateDataShape requires two type arguments.

0:26 We've got this here, where we're passing it two type arguments, and they're being put into the DataShape. We've got a data here and an error, but we want to somehow find a default for this TError to default it to undefined. Currently, it demands that we have to pass it.