-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add type arguments in transform decorator
- Loading branch information
Showing
4 changed files
with
44 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { plainToInstance, Transform } from '../../src'; | ||
|
||
interface CSVInvoiceRecord { | ||
net: string; | ||
} | ||
|
||
class Invoice { | ||
@Transform<CSVInvoiceRecord, 'net', number>(({ value }) => Number(value.replace(',', ''))) | ||
net: number; | ||
} | ||
|
||
const rawInvoice: CSVInvoiceRecord = { | ||
net: '2,000', | ||
}; | ||
|
||
const invoice = plainToInstance(Invoice, rawInvoice); | ||
console.log(invoice); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { TransformationType } from '../../enums'; | ||
import { ClassTransformOptions } from '../class-transformer-options.interface'; | ||
|
||
export interface TransformFnParams { | ||
value: any; | ||
export interface TransformFnParams<T extends Record<string, any> = any, K extends keyof T = any> { | ||
value: T[K]; | ||
key: string; | ||
obj: any; | ||
obj: T; | ||
type: TransformationType; | ||
options: ClassTransformOptions; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters