TypeScript-DOM-lib-generator icon indicating copy to clipboard operation
TypeScript-DOM-lib-generator copied to clipboard

Type "clipboard-write" is not assignable to type "PermissionName"

Open aminnairi opened this issue 3 years ago • 5 comments

Description

When using the Clipboard API, one might need to request permission for the clipboard-write in case we want to add something to the user's system clipboard if the user didn't already yield the permission.

Issue

When providing the clipboard-write permission to the window.navigator.permissions.query({name: "clipboard-write"}); method, the compiler throws an error saying that Type "clipboard-write" is not assignable to type "PermissionName".

Reproduction code

window.navigator.permissions.query({name: "clipboard-write"});

Typescript version

4.5.4

Additional context

It looks like the clipboard-write and clipboard-read permissions are not listed in the lib.dom.d.ts file for the PermissionName type, although they are part of the standard Clipboard API.

aminnairi avatar Jan 08 '22 16:01 aminnairi

Clipboard permissions are at risk:

  1. clipboard-read is officially removed from the spec: https://github.com/w3c/clipboard-apis/pull/132
  2. clipboard-write has no multiple implementer interest and thus will probably be removed too: https://github.com/w3c/clipboard-apis/issues/163

And thus I think this won't be solved, at least not anytime soon.

saschanaz avatar Jan 16 '22 21:01 saschanaz

Hi! So "officially" has been removed both clipboard-write and clipboard-read but in MDN Permissions API documentation they are already there? (even compatibility is not the best)

Also, I guess I can use navigator.clipboard.writeText() without requesting the user the permission?

Thank you.

EDIT: Sorry, clipboard-write is not officially removed but is not detected as a Permission Name when using Typescript...

jordihm9 avatar May 30 '22 08:05 jordihm9

Still relevant. Any updates? Way to solve this problem:

navigator.permissions.query({ name: "clipboard-write" as PermissionName }).then(result => {});

fresonn avatar Apr 25 '23 17:04 fresonn

clipboard-write is still a Blink-only thing as of today.

saschanaz avatar Apr 25 '23 18:04 saschanaz

@saschanaz. Oh, I got it. An open issue misled me, I thought it was an error ... Thanks

fresonn avatar Apr 25 '23 18:04 fresonn