Giter Club home page Giter Club logo

Comments (3)

mobily avatar mobily commented on May 21, 2024 2

@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:

expectType<typeof rec>(D.selectKeys(rec, keys))

from ts-belt.

Nodonisko avatar Nodonisko commented on May 21, 2024 2

@mobily Wow, thank you a lot! That significantly improves my DX :)

from ts-belt.

Nodonisko avatar Nodonisko commented on May 21, 2024

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)

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.