Effect CommunityEC
Effect Community14mo ago
4 replies
FORNO

Effect-TS Match Type Inference Returning Option<unknown> Instead of Option<number>

Hi everyone,

I'm using Effect-TS's Match utility to process input values and return an Option<number>. However, my implementation is currently yielding a result of type Option<unknown> instead of Option<number>.

Here's the relevant code snippet:

import {pipe, Match, Number, Option } from 'effect'

const a = pipe(
  Match.type<string | number | object>(),
  Match.when(Match.string, Number.parse),
  Match.when(Match.number, Option.some),
  Match.orElse(Option.none),
);

Details of expectations:

Number.parse is a function of type (s: string) => Option<number>. For strings, I expect this to return an Option<number>.
Numbers are directly wrapped in Option.some, so this branch should also produce an Option<number>.
For any other types (e.g., objects), they are handled by Option.none. As a result, all possible cases should lead to an Option<number>.
Given these conditions, I expect the type of a to be Option<number>. However, the inferred type is currently Option<unknown>.

Is there something I'm overlooking about how Match handles type inference, or is there an adjustment I can make to ensure the result is correctly typed as Option<number>?

Any advice would be greatly appreciated! Thank you!
image.png
Was this page helpful?