TypeScript
TypeScript copied to clipboard
typing for navigator.clipboard
⚙ Compilation target
ES5
⚙ Library
None
Missing / Incorrect Definition
lib.dom.ts defines interface Navigator with:
`/**
- Available only in secure contexts.
- MDN Reference */ readonly clipboard: Clipboard;`
This allows writing code like navigator.clipboard.readText() which crashes in unsecure environments (over HTTP).
Fix suggestion: Change the return type in typing to Clipboard | null to force a null check in consuming code. This is kind of a breaking change but that's the point.
Sample Code
navigator.clipboard.readText() ;will crash over HTTP
Documentation Link
No response