Effect CommunityEC
Effect Community2y ago
4 replies
leighman

Extending TypeScript Mapped Types to Support Multiple Contracts

I have a type like
type ParametersRefinements = {
  [K in ProductName as `is${K}`]: Refinement<Contract<any>, Contract<K>>
}

but I want to extend it to support a ReducedContract too
I want something like
type ParametersRefinements = {
  [K in ProductName as `is${K}`]: <C>(
    contract: C,
  ) => C extends Contract<any>
    ? contract is Contract<K>
    : contract is ReducedContract<K>
}

but that's not supported. anyone have ideas?
Was this page helpful?