Skip to content

Commit

Permalink
docs(readme): add example usage of the validate option
Browse files Browse the repository at this point in the history
  • Loading branch information
wagoid committed Jun 1, 2021
1 parent 631e550 commit 9b14a74
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,29 @@ export class Config {
}
```

## Custom validate function

If the default `validate` function doesn't suite your use case, you can provide it like in the example below:

```ts
TypedConfigModule.forRoot({
schema: RootConfig,
validate: (rawConfig: any) => {
const config = plainToClass(RootConfig, rawConfig)
const schemaErrors = validateSync(config, {
forbidUnknownValues: true,
whitelist: true,
})

if (schemaErrors.length) {
throw new Error(TypedConfigModule.getConfigErrorMessage(schemaErrors))
}

return config as RootConfig
},
})
```

## Using config outside Nest's IoC container (Usage in decorators)

### Caution!
Expand Down

0 comments on commit 9b14a74

Please sign in to comment.