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

Readme example doesn't typecheck #81

Open
ThomWright opened this issue Nov 2, 2017 · 0 comments
Open

Readme example doesn't typecheck #81

ThomWright opened this issue Nov 2, 2017 · 0 comments

Comments

@ThomWright
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant