Effect CommunityEC
Effect Community•2y ago•
4 replies
attila

`ReadonlyRecord.get` type error after Effect upgrade

I've just upgraded to effect@2.4.3 from 2.0.0-next.62 (a rather large jump, I know). And I've solved almost every type error (thanks a lot for the codemods!) except for this last one:
import { Option, ReadonlyArray, ReadonlyRecord } from "effect";
import { constant, flow } from "effect/Function";

export type SortBy = <SortKey extends string, A, B>(_: {
  keys: readonly SortKey[];
  getKey: (_: A) => SortKey;
  reduce: (_: A[]) => B;
}) => (self: readonly A[]) => Option.Option<B>[];

export const sortBy: SortBy = ({ keys, getKey, reduce }) =>
  keys.length === 0
    ? constant([])
    : flow(
        ReadonlyArray.groupBy(getKey),
        ReadonlyRecord.map(reduce),
        (selfByKey) =>
          // @ts-expect-error Type 'string' is not assignable to type 'NonLiteralKey<SortKey>'
          ReadonlyArray.map(keys, (key) => ReadonlyRecord.get(selfByKey, key))
      );

One could argue that this function does more than its name suggests but don't let that sidetrack you from the type error I'm getting there 😅 I'm new to this NoInfer keyword. Any idea what the right way of fixing this might be?
Was this page helpful?