Skip to content

Commit b8e6f27

Browse files
committed
docs(@nestjs/swagger): add new type helper
relate to nestjs/swagger#677
1 parent 3dd5e32 commit b8e6f27

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

content/recipes/swagger.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,37 @@ 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+
age: number;
264+
265+
@ApiProperty()
266+
breed: string;
267+
}
268+
269+
export class AdditionalCatInfo {
270+
@ApiProperty()
271+
color: string;
272+
}
273+
```
274+
275+
We can generate a new type that combines all properties in both types.
276+
277+
```typescript
278+
export class UpdateCatDto extends IntersectionType(CreateCatDto, AdditionalCatInfo) {}
279+
```
280+
281+
> info **Hint** The `IntersectionType()` function is imported from the `@nestjs/swagger` package.
282+
283+
253284
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:
254285

255286
```typescript

0 commit comments

Comments
 (0)