-
-
Notifications
You must be signed in to change notification settings - Fork 452
Description
Description
When using ky in Deno with deno check, the body property is not recognized on the Options type, even though Options extends Omit<RequestInit, 'headers'> which should include it.
Reproduction
import ky from 'npm:ky'
const api = ky.create({
prefixUrl: 'https://api.example.com',
headers: { authorization: 'Bearer test' },
})
const form = new URLSearchParams({ key: 'value' })
api.post('endpoint', { body: form })$ deno eval --check "
import ky from 'npm:ky'
const api = ky.create({ prefixUrl: 'https://example.com' })
const form = new URLSearchParams({ a: 'b' })
api.post('test', { body: form })
"
TS2353 [ERROR]: Object literal may only specify known properties, and 'body' does not exist in type 'Options'.
api.post('test', { body: form })
~~~~
Assigning Options directly also fails:
import type { Options } from 'npm:ky'
const o: Options = { body: 'test' }
// TS2353: 'body' does not exist in type 'Options'Meanwhile, the base type works fine in Deno:
const o: Omit<RequestInit, 'headers'> = { body: 'test' }
// OK - no errorEnvironment
- ky 1.14.3 (via
npm:ky) - Deno 2.1.9
Suspected root cause
Options is defined as:
export interface Options extends KyOptions, Omit<RequestInit, 'headers'> { ... }Deno's RequestInit type has body defined, and Omit<RequestInit, 'headers'> retains it. But when the interface merges KyOptions and Omit<RequestInit, 'headers'>, Deno's type checker loses the body property. This doesn't happen under Node/browser TypeScript — only under Deno's type checker. Likely a difference in how Deno's built-in RequestInit (from lib.deno.fetch.d.ts) interacts with the interface merge compared to the DOM lib RequestInit that ky was developed against.
At runtime, body works correctly — the issue is type-checking only.