#Extending complex types

3 messages · Page 1 of 1 (latest)

knotty osprey
#

I'm using ts-rest which does some extensive type inference like:

export type TsRestRequest<T extends AppRouter | AppRoute, F extends FlattenAppRouter<T> = FlattenAppRouter<T>, S extends ServerInferRequest<F> = ServerInferRequest<F>> = Request<'params' extends keyof S ? S['params'] : Express['request']['params'], ServerInferResponseBody<F>, 'body' extends keyof S ? S['body'] : Express['request']['body'], 'query' extends keyof S ? S['query'] : Express['request']['query']> & {
    tsRestRoute: F;
    headers: 'headers' extends keyof S ? S['headers'] : Express['request']['headers'];
};

Is there a way I can easily add a property to that type? specifically if I wanted to add an auth property.

stable pine
#

Something like this maybe?

export type MyCustomTsRestRequest<T extends AppRouter | AppRoute, F extends FlattenAppRouter<T> = FlattenAppRouter<T>, S extends ServerInferRequest<F> = ServerInferRequest<F>> = TsRestRequest<T, F, S> & { auth: string };
knotty osprey
#

is there no way to not have to add all of those types?