Skip to content

body property missing from Options type in Deno #837

@leizha

Description

@leizha

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 error

Environment

  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions