Comments (3)
@leviathan-n ts-belt
is using immutable arrays by default and frankly speaking, this is a common problem, I have added a possibility for using either immutable or mutable arrays
to use mutable arrays in the entire project, simply add the following in your global.d.ts
:
declare namespace Belt {
type UseMutableArrays = 1
}
although you may still want to use immutable arrays (which is a recommended approach), then starting from v3.11.0
you can use the F.toMutable
helper instead of the as
keyword:
const xs = pipe(
items,
A.map(…),
F.toMutable,
) // → PickerColumnItem[]
links:
https://mobily.github.io/ts-belt/docs/getting-started/config#immutable-vs-mutable
https://mobily.github.io/ts-belt/api/function#tomutable
@Nodonisko your case is different, D.selectKeys
and D.deleteKeys
had broken signatures, and it's been fixed in v3.11.0
as well 🚀 I have added a simple test to cover this case:
ts-belt/__tests__/Dict/selectKeys.test.ts
Line 16 in 3e27328
from ts-belt.
@mobily Wow, thank you a lot! That significantly improves my DX :)
from ts-belt.
This causing me lot of issues too, consider this example:
const obj = {foo: 1, bar: 2}
const myKeys = ['foo', 'bar'] as const;
D.selectKeys(obj, myKeys);
and this produce same error as mentioned The type 'readonly ["foo", "bar"]' is 'readonly' and cannot be assigned to the mutable type '("foo" | "bar")[]'
I really like this library but this is causing my lot of problems. Is really necessary for type to be mutable? I think it should work without any issue for readonly
since lib will never mutate passed params.
Thanks.
// edit:
One of possible workaround for these that are affected by this could be this:
type Writeable<T> = { -readonly [P in keyof T]-?: T[P] };
D.selectKeys(obj, myKeys as Writeable<typeof obj>);
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.