Comments (4)
@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.
@Nodonisko this is fixed in v4.0.0-rc.0
(the latest is v4.0.0-rc.1
)
from ts-belt.
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.
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
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)
- Add type guard compatible overload for `O.filter`
- Typescript error from Result example HOT 2
- Library reexport
- What is the recommended way of testing the value in an object? HOT 5
- a very simple request : N.toString HOT 1
- Handling generic typing for D.toPairs()
- Would a D.deleteOtherKeys be useful as part of the core? HOT 1
- F.getWithDefault Coercion type problem HOT 5
- Unsafe `isNone()` and `isSome()` type predicates HOT 1
- Ts-belt is 4x slower because it uses the arguments object
- Why an Option type instead of `type` | undefined? HOT 4
- Using unions for a result HOT 11
- ts-belt usage example flagged by TypeScript HOT 2
- why not `Do Notation` and `Applicative`
- Misleading annotations for Array.range
- Is this library still being maintained? HOT 1
- 🚧 Announcement: the current state of ts-belt 🚧 HOT 2
- `AR.isOk` and `AR.isError` not defined
- `AR.toOption` for `undefined` promise resolutions resulting in `{ BS_PRIVATE_NESTED_SOME_NONE: 0 }` HOT 1
- O.Option's functions with null literal value behaves differ from with undefined literal values HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ts-belt.