📜  class-transformer 默认值 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:25.654000             🧑  作者: Mango

代码示例1
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
}