radash icon indicating copy to clipboard operation
radash copied to clipboard

Feature request - pick with readonly array

Open stefaanMLB opened this issue 2 years ago • 3 comments

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)

stefaanMLB avatar Jul 07 '23 13:07 stefaanMLB

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

n-rowe avatar Apr 18 '24 09:04 n-rowe

Not that I know of

stefaanMLB avatar Apr 18 '24 11:04 stefaanMLB

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

aleclarson avatar Jul 09 '24 02:07 aleclarson