Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add helper function when for top-level match function#285

Merged
yuhr merged 2 commits intoruntypes:masterfrom
yuhr:feat/match-helper-when
Oct 27, 2021
Merged

Add helper function when for top-level match function#285
yuhr merged 2 commits intoruntypes:masterfrom
yuhr:feat/match-helper-when

Conversation

@yuhr
Copy link
Member

@yuhr yuhr commented Sep 15, 2021

This provides a workaround for #259. I couldn't find a real “fix” for the type inference problem. AFAIK it seems to be impossible to infer the parameter types of the case functions in the inner tuples, so I desided to provide a non-invasive helper function to get it inferred, when, which will also lead us to more readable code:

const f = match(
  when(Literal(42), fortyTwo => fortyTwo / 2),
  when(Number, n => n + 9),
  when(String, s => s.length * 2),
);

@yuhr yuhr merged commit 625e3fb into runtypes:master Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant