sodiray / radash

Functional utility library - modern, simple, typed, powerful
https://radash-docs.vercel.app
MIT License
4.18k stars 167 forks source link

Feature request - pick with readonly array #326

Open stefaanMLB opened 1 year ago

stefaanMLB commented 1 year ago

Have the Object pick function accept readonly string array of property names. Then it can work together with nestjs's PickType helper function which can use the same array, but requires it to be readonly.

Now, the below example doesn't work

import { PickType } from '@nestjs/mapped-types'
import { pick } from 'radash'

const FORM_PICKS = ['id', 'labelNl'] as const

export class FormDto extends PickType(ElabFormEntity, FORM_PICKS) {
  constructor(entity: ElabFormEntity) {
    super()
    Object.assign(this, pick(entity, FORM_PICKS))
  }
}

Fails with

Argument of type 'readonly ["id", "labelNl"]' is not assignable to parameter of type '(keyof ElabFormEntity)[]'.
  The type 'readonly ["id", "labelNl"]' is 'readonly' and cannot be assigned to the mutable type '(keyof ElabFormEntity)[]'.ts(2345)
n-rowe commented 4 months ago

I'm having a similar issue, is there a workaround for this?

stefaanMLB commented 4 months ago

Not that I know of

aleclarson commented 2 months ago

Hello @n-rowe. Over at the Radashi fork, we've fixed this issue. You can try it today by installing radashi@beta. See you over there!

https://github.com/radashi-org/radashi