TS2315

error TS2315: Type ‘CustomRequest‘ is not generic.

Broken Code ❌

1
2
3
4
5
6
7
8
9
type CustomRequest = {
url: string;
data: string;
};

const request: CustomRequest<string> = {
url: 'https://typescript.tv/',
data: 'example',
};

Fixed Code ✔️

When supplying a type (recognizable by the use of the diamond operator <>), then we have to make sure that our type actually supports generics to capture the type that we provide:

1
2
3
4
5
6
7
8
9
type CustomRequest<CustomType> = {
url: string;
data: CustomType;
};

const request: CustomRequest<string> = {
url: 'https://typescript.tv/',
data: 'example',
};