From ffe2872784f5883b58d210f6b04c1638a0910ba2 Mon Sep 17 00:00:00 2001 From: Mihir Kumar Date: Wed, 23 Oct 2019 21:40:35 +0530 Subject: [PATCH] Consistent return type introduced --- .eslintrc.js | 1 - src/client/copyToClipboard.ts | 10 +++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index b483a62..a1e07b0 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -20,7 +20,6 @@ module.exports = { 'func-style': ['error', 'declaration', { allowArrowFunctions: true }], 'no-use-before-define': ['error', { functions: false }], '@typescript-eslint/no-use-before-define': ['error', { functions: false }], - 'consistent-return': 1 }, settings: { 'import/resolver': { diff --git a/src/client/copyToClipboard.ts b/src/client/copyToClipboard.ts index 4b8e608..388aade 100644 --- a/src/client/copyToClipboard.ts +++ b/src/client/copyToClipboard.ts @@ -1,7 +1,8 @@ // NOTE text selection on double click or select -const copyToClipboard = (text: string) : any => { +const copyToClipboard = (text: string) : boolean => { if (window.clipboardData && window.clipboardData.setData) { - return window.clipboardData.setData("Text", text); + window.clipboardData.setData("Text", text); + return true; } if (document.queryCommandSupported && document.queryCommandSupported("copy")) { const textarea = document.createElement("textarea"); textarea.textContent = text; @@ -9,7 +10,8 @@ const copyToClipboard = (text: string) : any => { document.body.appendChild(textarea); textarea.select(); try { - return document.execCommand("copy"); + document.execCommand("copy"); + return true; } catch (ex) { console.warn("Copy to clipboard failed.", ex); return false; @@ -17,6 +19,8 @@ const copyToClipboard = (text: string) : any => { document.body.removeChild(textarea); } } + console.warn("Copy to clipboard failed."); + return false; } export default copyToClipboard; \ No newline at end of file