# Decorator GenericOf
Decorator validation swagger schema input genericsModule | import { GenericOf } from "@tsed/schema" |
---|---|
Source | /packages/schema/src/decorators/generics/genericOf.ts |
# Overview
function GenericOf(...generics: Type<any>[]): GenericOfChainedDecorators;
# Description
Set the types of a Generic class.
# Example
class Product {
@Property()
label: string;
}
@Generics("T")
class Paginated<T> {
@CollectionOf("T")
data: T[];
@Property()
totalCount: number;
}
class Payload {
@GenericOf(Product)
products: Paginated<Product>;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Example with nested generics
class Product {
@Property()
label: string;
}
@Generics("T")
class Paginated<T> {
@CollectionOf("T")
data: T[];
@Property()
totalCount: number;
}
@Generics("D")
class Submission<D> {
@Property()
_id: string;
@Property("D")
data: D;
}
class Payload {
@GenericOf(Submissions).Nested(Product)
submissions: Paginated<Submission<Product>>;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Other topics
- Session & cookies
- Passport.js
- TypeORM
- Mongoose
- GraphQL
- Socket.io
- Swagger
- AJV
- Multer
- Serve static files
- Templating
- Throw HTTP Exceptions
- Customize 404
- AWS
- Seq
- OIDC
- Stripe
- Controllers
- Providers
- Model
- JsonMapper
- Middlewares
- Pipes
- Interceptors
- Authentication
- Hooks
- Exceptions
- Hooks
- Response Filter
- Injection scopes
- Custom providers
- Custom endpoint decorator
- Testing