Closed
Description
TypeScript Version: 2.8.1
Search Terms:
selectionStart, selectionEnd
Code
// Source code from https://github.com/styfle/copee
function fromElement(el: HTMLInputElement | HTMLTextAreaElement, preserveSelection?: boolean) {
let start = 0;
let end = 0;
let success = false;
if (preserveSelection) {
start = el.selectionStart;
end = el.selectionEnd;
}
el.select();
try {
success = document.execCommand('copy');
} catch (err) {
success = false;
}
if (preserveSelection) {
el.setSelectionRange(start, end);
}
return success;
}
Expected behavior:
el.selectionStart and el.selectionEnd should return number
Actual behavior:
el.selectionStart and el.selectionEnd actually return number | null
Playground Link:
Playground
Related Issues:
#22381 , styfle/copee#21