radash
radash copied to clipboard
Feature request - pick with readonly array
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)
I'm having a similar issue, is there a workaround for this?
Not that I know of
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