rsnext/packages/next/lib/pick.ts
Gal Schlezinger 88d0440ad4
[middleware] Support any method when fetching a Request instance (#37540)
There was a bug that ignored `Request` options when one was given to the `fetch` function:

```ts
const request = new Request("https://example.vercel.sh", { method: "POST" });
await fetch(request);
```

The code above was expected to make a `POST` request, but instead it
made a `GET` request.

This commit fixes it and adds some tests to verify that fetching with a
`Request` object works as expected, and therefore resolves #37123.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-06-08 11:00:49 +00:00

7 lines
187 B
TypeScript

export function pick<T, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {
const newObj = {} as Pick<T, K>
for (const key of keys) {
newObj[key] = obj[key]
}
return newObj
}