Giter Club home page Giter Club logo

Comments (4)

Nodonisko avatar Nodonisko commented on May 18, 2024 1

@ivan-kleshnin You can probably wrap pairs in F.toMutable(pairs) to solve issue, but I agree with you that readonly are very problematic. I already created this issue about them #65

from ts-belt.

mobily avatar mobily commented on May 18, 2024

@Nodonisko this is fixed in v4.0.0-rc.0 (the latest is v4.0.0-rc.1)

CleanShot 2022-12-04 at 18 37 56@2x

from ts-belt.

Nodonisko avatar Nodonisko commented on May 18, 2024

Thanks, sadly I can't use rc version for our app, but soon as it will be released I will try it.

from ts-belt.

ivan-kleshnin avatar ivan-kleshnin commented on May 18, 2024

I also have problems with A.groupBy due to the way it's typed:

import {A, D, pipe} from "@mobily/ts-belt"

function groupErrors(errors: Dict<string>): Dict<string[]> {
  return pipe(
    errors,
    D.toPairs,
    A.groupBy(pair => pair[1]), 
    D.map((pairs: any): string[] => // <-- remove this `any` suppressor to see an issue
      A.map(pairs, (pair: [string, string]) => pair[0])
    )
  )
}

console.log(groupErrors({
  login1: "NotFoundError",
  login2: "NotFoundError",
  login3: "TimeoutError",
  login4: "TimeoutError",
}))

// ->
const result = {
  NotFoundError: ["login1", "login2"],
  TimeoutError: ["login3", "login4"]
}
void result

Screen Shot 2023-01-10 at 13 46 49

Original typing:

export declare function groupBy<A>(xs: Array<A>, groupFn: (item: A) => PropertyKey): Record<PropertyKey, readonly [A, ...A[]]>;
export declare function groupBy<A>(groupFn: (item: A) => PropertyKey): (xs: Array<A>) => Record<PropertyKey, readonly [A, ...A[]]>;

The example code above works fine with:

export declare function groupBy<A>(xs: Array<A>, groupFn: (item: A) => PropertyKey): Record<PropertyKey, Array<A>>;
export declare function groupBy<A>(groupFn: (item: A) => PropertyKey): (xs: Array<A>) => Record<PropertyKey, Array<A>>;

Change: readonly [A, ...A[]]> --> Array<A>

In my experience readonly modifiers bring more harm than good 😞

from ts-belt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.