TS2315
Type 'CustomRequest' is not generic.
Broken Code ❌
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:
type CustomRequest<CustomType> = {
url: string;
data: CustomType;
};
const request: CustomRequest<string> = {
url: 'https://typescript.tv/',
data: 'example',
};