Skip to content

Commit 8282bd5

Browse files
Merge pull request #1165 from Diluka/swagger-type-helper
docs(@nestjs/swagger): add new type helper
2 parents 35c2732 + c1a3d3e commit 8282bd5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

content/recipes/swagger.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,34 @@ export class UpdateCatDto extends OmitType(CreateCatDto, ['name']) {}
250250

251251
> info **Hint** The `OmitType()` function is imported from the `@nestjs/swagger` package.
252252
253+
The `IntersectionType()` function combines two types into one new type (class). For example, suppose we start with two types like:
254+
255+
```typescript
256+
import { ApiProperty } from '@nestjs/swagger';
257+
258+
export class CreateCatDto {
259+
@ApiProperty()
260+
name: string;
261+
262+
@ApiProperty()
263+
breed: string;
264+
}
265+
266+
export class AdditionalCatInfo {
267+
@ApiProperty()
268+
color: string;
269+
}
270+
```
271+
272+
We can generate a new type that combines all properties in both types.
273+
274+
```typescript
275+
export class UpdateCatDto extends IntersectionType(CreateCatDto, AdditionalCatInfo) {}
276+
```
277+
278+
> info **Hint** The `IntersectionType()` function is imported from the `@nestjs/swagger` package.
279+
280+
253281
The type mapping utility functions are composable. For example, the following will produce a type (class) that has all of the properties of the `CreateCatDto` type except for `name`, and those properties will be set to optional:
254282

255283
```typescript

0 commit comments

Comments
 (0)