Narrowing Response Types Based on Route in TypeScript Match Implementation

Can you "narrow" a Match? I have a Match that matches on a value of
routes


so my implementation is like this

get: (_route, init) => {
    const result = Match.value(_route).pipe(
      Match.when('/tokens', () =>
        Effect.succeed({ status: 200 as const, body: tokenResponseBody }),
      ),
      Match.when('/userinfo', () =>
        Effect.succeed({ status: 200 as const, body: userInfoResponse }),
      ),
      Match.when('/authorize', () => pipe(init['query'], getFirstElementAndRespond)),
      Match.exhaustive,
    );
    return result;
  }


Which is fine, the actual type in the handler though thinks that this can return 3 different types of response objects.

I'd like to be able to narrow based on the route I pass in, that it should know it can't return the other 2.
Was this page helpful?