satyarohith / sift

Sift is a routing and utility library for Deno Deploy.

Home Page:https://deno.land/x/sift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

usage of spread operator with HeadersInit leads to unexpected behavior or errors

jsejcksn opened this issue · comments

Here's an example from json:

sift/mod.ts

Lines 227 to 252 in 424d5b7

/** Converts an object literal to a JSON string and returns
* a Response with `application/json` as the `content-type`.
*
* @example
* ```js
* import { serve, json } from "https://deno.land/x/sift/mod.ts"
*
* serve({
* "/": () => json({ message: "hello world"}),
* })
*```
* */
export function json(
// deno-lint-ignore no-explicit-any
jsobj: any,
init?: ResponseInit,
): Response {
return new Response(JSON.stringify(jsobj) + "\n", {
statusText: init?.statusText ?? STATUS_TEXT.get(init?.status ?? Status.OK),
status: init?.status ?? Status.OK,
headers: {
"Content-Type": "application/json; charset=utf-8",
...init?.headers,
},
});
}

On line 249, init.headers is of type HeadersInit (which is Headers | string[][] | Record<string, string>). However, if it is not Record<string, string>, this usage of the spread operator will lead to unexpected behavior or errors.