question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generated code breaks after update to TypeScript 2.6.1

See original GitHub issue

Hi,

Since we’ve updated to TypeScript 2.6.1 the generated output breaks our build. This is due to the headers in the output which don’t conform to the new RequestInit interface in lib.dom.ts. In the old version it accepted a <any> type for the headers property but now it only accepts <Headers | string[][]>.

For now we can simply solve this by reverting to TypeScript version 2.5.3.

Is there a way to influence the way the headers get generated?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
MariuszKogutcommented, Nov 7, 2017

Assigning an object {} to header is not specified by MDN, but supported by the browser. We are using an fetch Decorator to set the token. In the old version, setting headers.Authorization works fine.

const fetchDecorator = {
  fetch(url: any, init?: RequestInit): Promise<Response> {
    const token = 'Bearer ' + identityManager.getToken();
    if (init) {
      init.headers.Authorization = token;
      init.credentials = 'include';
    }
    return window.fetch(url, init);
  }
};

Now we have to use the headers.set method, to inject the token.

const fetchDecorator = {
  fetch(url: any, init?: RequestInit): Promise<Response> {
    const token = 'Bearer ' + identityManager.getToken();
    if (init) {
      const headers = init.headers as Headers;
      headers.set('Authorization', token);
      init.credentials = 'include';
    }
  return window.fetch(url, init);
  }
};
1reaction
huubhermsencommented, Nov 2, 2017

Works like a charm!

Thank you for the speedy solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

d.ts not compiling after TypeScript 2.6.1
This is mentioned on the breaking changes page. Export assignments like the one in question are executable code, and 2.6.1 was made more ......
Read more >
Documentation - TypeScript 3.9
We heard from the Visual Studio Code team that when renaming a file, just figuring out which import statements needed to be updated...
Read more >
October 2017 (version 1.18)
VS Code 1.18 ships with TypeScript 2.6.1. This update provides VS Code with several exciting tooling improvements and also fixes a few bugs....
Read more >
Use TypeScript to Build a Node API with Express
Use TypeScript to Build a Node API with Express This tutorial walks you through building a simple and secure Node application using ...
Read more >
MakeCode Languages: Blocks, Static TypeScript and Static ...
Both Blocks and Static Python are converted to Static TypeScript before being compiled to lower-level languages. Blocks is implemented using Google Blockly.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found