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

Property 'permissions' does not exist on type 'Navigator' #24923

Closed
mdwekat opened this issue Jun 13, 2018 · 12 comments
Closed

Property 'permissions' does not exist on type 'Navigator' #24923

mdwekat opened this issue Jun 13, 2018 · 12 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Suggestion An idea for TypeScript

Comments

@mdwekat
Copy link

mdwekat commented Jun 13, 2018

TypeScript Version:
2.7.2

Search Terms:
Property 'permissions' does not exist on type 'Navigator'

Code

const perm = navigator.permissions;
    perm.query({name: 'geolocation'})
      .then(permissionStatus => {
        console.log('geolocation permission state is ', permissionStatus.state);
        permissionStatus.onchange = () => {
          console.log('geolocation permission state has changed');
        };
      });

Expected behavior:
navigator.permissions should be defined
Actual behavior:
navigator.permissions does not exist.

Playground Link:
https://goo.gl/5ckgwD

Related Issues:
#16246

@kitsonk
Copy link
Contributor

kitsonk commented Jun 13, 2018

The Permissions API is quite in draft status at the moment. It may not make sense to add this, as it is only supported by Chrome-based and Firefox. Adding these yourself should be possible. The API isn't even listed on Edge platform status, and the Chrome status indicates it is just a working draft.

@mhegazy mhegazy added Suggestion An idea for TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Jun 13, 2018
@jwalton
Copy link

jwalton commented Oct 29, 2018

npm install --save-dev @types/w3c-permissions, for those looking for a work-around.

@weswigham weswigham added the Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature label Nov 6, 2018
@saschanaz
Copy link
Contributor

saschanaz commented Nov 12, 2018

Recently the TS team have merged several draft-status web features into lib.d.ts because future migration to lib.d.ts from DefinitelyTyped packages can be annoying. Read more at #18480 (comment) for the previous discussion.

In this case, IMO it can be added to lib.d.ts as the official spec exists and multiple major vendors provide their implementations.

@vincevargadev
Copy link

vincevargadev commented Jan 7, 2019

We also created types for the permissions API and submitted to DefinitelyTyped repository. We used the MDN Permissions page to add documentation using TSDoc. You can check the examples, if not clear how to use it.

You can check it on npm and install it as dev dependency by:

$ npm install --save-dev @types/navigator-permissions

Feedback is welcome.

Update: it was removed from DefinitelyTyped repository in DefinitelyTyped/DefinitelyTyped#34641 as a separate type definition isn't needed in TypeScript 3.5+. NPM should still work.

@romain-faust
Copy link

romain-faust commented Jan 7, 2019

@vargavince91 very good job !
There is only one thing that I want to point out. As stated here, the revoke descriptor does not accept the same name parameter as the query one does.

Query : 'accelerometer', 'accessibility-events', 'ambient-light-sensor', 'background-sync', 'camera'​, 'clipboard-read', 'clipboard-write', 'geolocation', 'gyroscope', 'magnetometer', 'microphone', 'midi', 'notifications', 'payment-handler', 'persistent-storage', 'push'

Revoke : 'geolocation', 'midi', 'notifications', 'push'

@vincevargadev
Copy link

Oh thank you for pointing this out, I'm going to submit a merge request today with the fixes

@bennycode
Copy link
Contributor

We also created types for the permissions API and submitted to DefinitelyTyped repository. We used the MDN Permissions page to add documentation using TSDoc.

@vargavince91 Super nice that you wrote types for it! Do you may also have types for navigator.clipboard?

@ProtocolNebula
Copy link

I have the same problem, but in some computers (maybe fault of node version) don't recognize the @types, so, additionally to that, I casted to any:

return (navigator as any).permissions.query({
  name: 'geolocation'
}).then((permission) => {
    console.log(permission);
});

@audiolion
Copy link

@saschanaz or @sandersn I see that these types were updated in the generator, but I dont see them in master

https://github.com/Microsoft/TypeScript/blob/9509a54e66034c7ae723051a3c79afaa9084046e/lib/lib.dom.d.ts#L10506

am I looking in the wrong place? have they not been released yet?

@sandersn
Copy link
Member

sandersn commented May 1, 2019

@audiolion Take a look in src/lib/dom.generated.d.ts instead. lib/ has the built library files in it, generated by running --LKG if I remember correctly.

@audiolion
Copy link

@sandersn sorry for the naïveté, but I dont see src/lib/dom.generated.d.ts in this repo, I see it in the TSJS-lib-generator one, I thought it somehow got translated over here by running the generator? hah. I guess my main issue is that using typescript 3.4.5 (current latest), I cant seem to find those new Navigator.permission types that were merged into the TSJS repo 28 days ago.

@dartess
Copy link

dartess commented Aug 5, 2019

for googling: Navigator.permission types in typescript@3.5.3 works fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests