Skip to content
This repository was archived by the owner on Aug 20, 2020. It is now read-only.
This repository was archived by the owner on Aug 20, 2020. It is now read-only.

Readme example doesn't typecheck #81

Open
@ThomWright

Description

@ThomWright

Intended outcome:

The middleware example in the readme should typecheck when used in Typescript:

apolloFetch.use(({ request, options }, next) => {
  if (!options.headers) {
    options.headers = {};  // Create the headers object if needed.
  }
  options.headers['authorization'] = 'created token';

  next();
});

Actual outcome:

An empty object cannot be assigned to options.headers:

message: 'Type '{}' is not assignable to type 'Headers | string[][] | undefined'.
  Type '{}' is not assignable to type 'string[][]'.
    Property 'includes' is missing in type '{}'.'

Apparently options.headers is either string[][] or Headers, where Headers seems to be (from the dom lib in the Typescript compiler options below):

interface Headers {
    append(name: string, value: string): void;
    delete(name: string): void;
    forEach(callback: ForEachCallback): void;
    get(name: string): string | null;
    has(name: string): boolean;
    set(name: string, value: string): void;
}

How to reproduce the issue:

Typescript compiler options:

{
  "compilerOptions": {
    "outDir": "./dist",
    "allowJs": true,
    "target": "es2017",
    "module": "commonjs",
    "lib": ["esnext", "esnext.asynciterable", "es2017", "dom"],
    "noUnusedLocals": true,
    "noErrorTruncation": true,
    "strict": true
  }
}

If there's anything else you need to be able to reproduce, let me know and I'll try to help out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions