Reputation: 4721
Why does Promise<any>
seem to have a "Wozniak free pass for life" in that situation?
Shouldn't it comply to the return type of Layer
(Promise<Response>
)?
What is the correct way to enforce Promise<Response>
as the return type?
type Layer = (req: Request) => Promise<Response>;
type Middleware = (next: Layer) => Layer;
export const json: Middleware = (next: Layer) => async (req: Request) => {
const res = await next(req);
if (res.headers.get('Content-Type') === 'application/json') {
const data = await res.json();
return data; // -> Type "any" - No TS error, why ??
}
return res; // -> Type "Response" - All good
};
Upvotes: 0
Views: 57