TypeScript: Missing `Navigator.clipboard` (clipboard asynchronous API)
TypeScript Version: 3.0.0-dev.20180711
Search Terms: navigator, clipboard
Code
console.log(window.navigator.clipboard)
Expected behavior: No error.
Actual behavior:
error TS2339: Property 'clipboard' does not exist on type 'Navigator'
Playground Link: http://www.typescriptlang.org/play/#src=window.navigator.clipboard%3B
Related Issues: none found
W3C: https://www.w3.org/TR/clipboard-apis/#async-clipboard-api MDN: https://developer.mozilla.org/en-US/docs/Web/API/Clipboard
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 15
- Comments: 22 (4 by maintainers)
Hey, isn’t it a good moment to go back to this issue and reopen it? I would really love to have it to avoid any workarounds. Chrome supports it from v66 now I have v71. Should be pretty stable.
How is “widely adopted” defined? It seems to me that according to http://gs.statcounter.com/ over half of all desktop browser users globally were on a Chrome version that supported this API already for months when the comment “We don’t add non-standard DOM APIs until they’re at least widely adopted.” was made.
Perhaps not a great solution but if anyone else needs a hacky workaround, this worked for me.
type new var with any
assign new var to window.navigator
use new var in place of navigator
seems to work ok with
"typescript": "^3.2.4"We don’t add non-standard DOM APIs until they’re at least widely adopted.
Where should I place this file?
It is an experimental API. By the way,
readTextandwriteTextare also supported in Firefox 63+.As a workaround:
Can anyone please share how to do this?
Both Chrome and Firefox support the clipboard
readandwritemethods now . Those should be added to the type definitions (which currently only containreadTextandwriteText).@1valdis it’s very reasonable that Typescript would not include these tools by default. Typescript is targeted to a very wide ranging audience. Giving bleeding-edge tools without warning and by default to developers who are unaware they might be bleeding edge easily leads to unknown bugs. TS is designed to prevent exactly these kinds of issues.
If you’re keen to use experimental tools, then you should also be aware of how to extend your definition files to allow them, and how to support users who do not have the latest browsers.
https://github.com/Microsoft/TypeScript/blob/2f9218f/src/lib/dom.generated.d.ts#L10489