From 5a7e415e36c36067d7363a0a2aef890308d7e1a7 Mon Sep 17 00:00:00 2001
From: Blazej Kustra <blazej.kustra@swmansion.com>
Date: Tue, 29 Aug 2023 21:20:41 +0200
Subject: [PATCH 1/3] [TS migration] Migrate 'setSelection' lib to TypeScript

---
 src/libs/setSelection/index.js        |  7 -------
 src/libs/setSelection/index.native.js |  7 -------
 src/libs/setSelection/index.native.ts | 14 ++++++++++++++
 src/libs/setSelection/index.ts        | 13 +++++++++++++
 src/libs/setSelection/types.ts        |  5 +++++
 src/types/modules/react-native.d.ts   |  8 ++++++++
 6 files changed, 40 insertions(+), 14 deletions(-)
 delete mode 100644 src/libs/setSelection/index.js
 delete mode 100644 src/libs/setSelection/index.native.js
 create mode 100644 src/libs/setSelection/index.native.ts
 create mode 100644 src/libs/setSelection/index.ts
 create mode 100644 src/libs/setSelection/types.ts
 create mode 100644 src/types/modules/react-native.d.ts

diff --git a/src/libs/setSelection/index.js b/src/libs/setSelection/index.js
deleted file mode 100644
index c7f24ae4a199..000000000000
--- a/src/libs/setSelection/index.js
+++ /dev/null
@@ -1,7 +0,0 @@
-export default function setSelection(textInput, start, end) {
-    if (!textInput) {
-        return;
-    }
-
-    textInput.setSelectionRange(start, end);
-}
diff --git a/src/libs/setSelection/index.native.js b/src/libs/setSelection/index.native.js
deleted file mode 100644
index 02d812d84cd4..000000000000
--- a/src/libs/setSelection/index.native.js
+++ /dev/null
@@ -1,7 +0,0 @@
-export default function setSelection(textInput, start, end) {
-    if (!textInput) {
-        return;
-    }
-
-    textInput.setSelection(start, end);
-}
diff --git a/src/libs/setSelection/index.native.ts b/src/libs/setSelection/index.native.ts
new file mode 100644
index 000000000000..75089c6a737d
--- /dev/null
+++ b/src/libs/setSelection/index.native.ts
@@ -0,0 +1,14 @@
+/* eslint-disable no-console */
+import SetSelection from './types';
+
+const setSelection: SetSelection = (textInput, start, end) => {
+    if (!textInput) {
+        return;
+    }
+
+    if ('setSelection' in textInput) {
+        textInput.setSelection(start, end);
+    }
+};
+
+export default setSelection;
diff --git a/src/libs/setSelection/index.ts b/src/libs/setSelection/index.ts
new file mode 100644
index 000000000000..5eee88881924
--- /dev/null
+++ b/src/libs/setSelection/index.ts
@@ -0,0 +1,13 @@
+import SetSelection from './types';
+
+const setSelection: SetSelection = (textInput, start, end) => {
+    if (!textInput) {
+        return;
+    }
+
+    if ('setSelectionRange' in textInput) {
+        textInput.setSelectionRange(start, end);
+    }
+};
+
+export default setSelection;
diff --git a/src/libs/setSelection/types.ts b/src/libs/setSelection/types.ts
new file mode 100644
index 000000000000..f2717079725f
--- /dev/null
+++ b/src/libs/setSelection/types.ts
@@ -0,0 +1,5 @@
+import {TextInput} from 'react-native';
+
+type SetSelection = (textInput: TextInput | HTMLInputElement, start: number, end: number) => void;
+
+export default SetSelection;
diff --git a/src/types/modules/react-native.d.ts b/src/types/modules/react-native.d.ts
new file mode 100644
index 000000000000..ab7e389c5397
--- /dev/null
+++ b/src/types/modules/react-native.d.ts
@@ -0,0 +1,8 @@
+/* eslint-disable @typescript-eslint/consistent-type-definitions */
+import 'react-native';
+
+declare module 'react-native' {
+    interface TextInput {
+        setSelection: (start: number, end: number) => void;
+    }
+}

From 7fe7fe5c9e297e500d087637472713c491f222cd Mon Sep 17 00:00:00 2001
From: Blazej Kustra <blazej.kustra@swmansion.com>
Date: Wed, 30 Aug 2023 11:05:40 +0200
Subject: [PATCH 2/3] Add comment

---
 src/types/modules/react-native.d.ts | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/types/modules/react-native.d.ts b/src/types/modules/react-native.d.ts
index ab7e389c5397..1b0b39e5f67d 100644
--- a/src/types/modules/react-native.d.ts
+++ b/src/types/modules/react-native.d.ts
@@ -3,6 +3,7 @@ import 'react-native';
 
 declare module 'react-native' {
     interface TextInput {
+        // Typescript type declaration is missing in React Native for setting text selection.
         setSelection: (start: number, end: number) => void;
     }
 }

From a5df84ad3bd1f43f7f658335a964a36d2c49e75a Mon Sep 17 00:00:00 2001
From: Blazej Kustra <blazej.kustra@swmansion.com>
Date: Mon, 4 Sep 2023 09:21:41 +0200
Subject: [PATCH 3/3] Remove eslint comment

---
 src/libs/setSelection/index.native.ts | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/libs/setSelection/index.native.ts b/src/libs/setSelection/index.native.ts
index 75089c6a737d..e27cd4e58bd7 100644
--- a/src/libs/setSelection/index.native.ts
+++ b/src/libs/setSelection/index.native.ts
@@ -1,4 +1,3 @@
-/* eslint-disable no-console */
 import SetSelection from './types';
 
 const setSelection: SetSelection = (textInput, start, end) => {
