Skip to content

lib.d.ts has a wrong definition of HeadersInit #19656

Closed

Description

TypeScript Version: 2.6.1 (and 2.7.0-dev.20171101)

Code

https://www.typescriptlang.org/play/index.html#src=fetch(%27%2Fsome-url%27%2C%20%7B%20headers%3A%20%7B%20%27Some-Header-Name%27%3A%20%27Value%27%20%7D%20%7D)%3B

fetch('/some-url', { headers: { 'Some-Header-Name': 'Value' } });

Expected behavior:
No errors.

Actual behavior:
Error:

Object literal may only specify known properties, and ''Some-Header-Name'' does not exist in type 'Headers | string[][]'.

According the spec RequestInit may has headers prop as HeadersInit type which is

type HeadersInit = [string, string][] | { [key: string]: string };

But currently we have Headers instead of map object in RequestInit.headers (the code above works fine in all browsers (including Edge)).

Also HeadersInit is not used in RequestInit.

Activity

  1. mhegazy commented on Nov 1, 2017

    @mhegazy
    Contributor

    PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes.

  2. added
    FixedA PR has been merged for this issue
    and removed
    Fixed in TSJS repoFix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet
    on Nov 21, 2017
  3. mikemonji commented on Jan 10, 2018

    @mikemonji

    Instead of:

    fetch('/some-url', { headers: { 'Some-Header-Name': 'Value' } });

    Try:

    let headers: any = { headers: { 'Some-Header-Name': 'Value' } };

    fetch('/some-url', headers);

  4. locked and limited conversation to collaborators on Jul 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issueHelp WantedYou can do this

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions