Answers for "class-transformer default value"

0

class-transformer default value

import { Transform, Expose } from 'class-transformer'
import { cloneDeep } from 'lodash'

export function Default(defaultValue: unknown): PropertyDecorator {
  return Transform((value: unknown) => value ?? cloneDeep(defaultValue))
}
                   
class A {
  @Expose()
  @Default('123')
  a: string
}
Posted by: Guest on December-24-2020

Code answers related to "TypeScript"

Browse Popular Code Answers by Language