Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript error TS2339: Property 'referrer' does not exist on type 'OnCompletedDetails'. #16660

Closed
partap opened this issue Jan 31, 2019 · 5 comments
Assignees

Comments

@partap
Copy link

partap commented Jan 31, 2019

  • Output of node_modules/.bin/electron --version: v4.0.3
  • Operating System (Platform and Version): OS X v10.13.6

Expected Behavior
in webRequest.onCompleted() handler, we are passed a details object of type OnCompletedDetails which contains a referrer attribute.

Actual behavior
Both the documentation for weebRequest and type definition of OnCompletedDetails omit the referrer attribute, but it is there.

I was initially concerned about this, because I'm updating an existing electron 2.x app to electron 4.x. The app had a webContents did-get-response-details event handler, which has been removed in electron 4.x, and the handler requires the referrer attribute to work.

However, when I added a hander for webRequest.onCompleted and inspected the details object I was happy to find that it does indeed set the referrer attribute. The only issue now is that the typescript compiler complains when I access it:

error TS2339: Property 'referrer' does not exist on type 'OnCompletedDetails'.

As of now, I'm just casting it as any to get around the compile error.

To Reproduce
I don't think full repo is necessary on this one. Just add this in any electron app (main process) and compile with typescript (using typescript v3.2.4 in this case)

import {session} from 'electron'

session.defaultSession.onCompleted((details) => {
  console.log('onCompleted:', details.referrer)
})

Solution
The type definition for OnCompletedDetails just needs an additional line.

electron.d.ts:

interface OnCompletedDetails {
  ...
  referrer: string;
}
@welcome
Copy link

welcome bot commented Jan 31, 2019

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.

@partap
Copy link
Author

partap commented Jan 31, 2019

So I just cloned electron to try to find the definition and realized this issue might belong in electron-typescript-definitions

@codebytere codebytere self-assigned this Jan 31, 2019
@partap
Copy link
Author

partap commented Jan 31, 2019

Aha... looks like the typescript definitions are automatically generated from the API docs. Pretty cool. I guess the solution is actually to update the docs for webRequest.onCompleted to include the referrer attribute.

@codebytere
Copy link
Member

Yep! i have a PR, it'll be up imminently

@partap
Copy link
Author

partap commented Jan 31, 2019

@codebytere Thanks! 25 minutes lol

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

No branches or pull requests

2 participants