react-native-selectable-text
react-native-selectable-text copied to clipboard
Lib with typescript errors
When the lib is added to the project and for example, this import import { SelectableText } from '@alentoma/react-native-selectable-text' is added to any typescript file, it generates this errors if we try to run tsc
Add this to some file in a react-native Typescript project
import {SelectableText} from '@alentoma/react-native-selectable-text';
Run this command:
yarn tsc
Typescript errors:
Try `npm i --save-dev @types/uuid` if it exists or add a new declaration (.d.ts) file containing `declare module 'uuid';`
3 import { v4 } from 'uuid'
~~~~~~
node_modules/@alentoma/react-native-selectable-text/demo/SelectableText.tsx:116:15 - error TS2322: Type 'string | number | true | ReactElement<any, string | JSXElementConstructor<any>> | ReactFragment | typeof Text' is not assignable to type 'ReactNode'.
Type 'typeof Text' is not assignable to type 'ReactNode'.
116 const TX = (TextComponent = TextComponent || Text) as Function;
~~~~~~~~~~~~~
node_modules/@alentoma/react-native-selectable-text/demo/SelectableText.tsx:127:26 - error TS7031: Binding element 'clickedRangeStart' implicitly has an 'any' type.
127 nativeEvent: { clickedRangeStart, clickedRangeEnd }
~~~~~~~~~~~~~~~~~
node_modules/@alentoma/react-native-selectable-text/demo/SelectableText.tsx:127:45 - error TS7031: Binding element 'clickedRangeEnd' implicitly has an 'any' type.
127 nativeEvent: { clickedRangeStart, clickedRangeEnd }
~~~~~~~~~~~~~~~
node_modules/@alentoma/react-native-selectable-text/demo/SelectableText.tsx:145:7 - error TS2367: This condition will always return 'false' since the types 'string | number | boolean | ReactElement<any, string | JSXElementConstructor<any>> | ReactFragment | ReactPortal | null | undefined' and 'typeof Text' have no overlap.
145 if (TextComponent == Text) {
~~~~~~~~~~~~~~~~~~~~~
node_modules/@alentoma/react-native-selectable-text/demo/SelectableText.tsx:150:58 - error TS2551: Property 'onPress' does not exist on type 'TextProps | TextInputProps'. Did you mean 'onPressIn'?
Property 'onPress' does not exist on type 'TextInputProps'.
150 if (textComponentProps && textComponentProps.onPress)
~~~~~~~
node_modules/@alentoma/react-native-selectable-text/demo/SelectableText.tsx:151:34 - error TS2551: Property 'onPress' does not exist on type 'TextProps | TextInputProps'. Did you mean 'onPressIn'?
Property 'onPress' does not exist on type 'TextInputProps'.
151 textComponentProps.onPress();
~~~~~~~
node_modules/@alentoma/react-native-selectable-text/index.ts:1:44 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
1 export { SelectableText as SelectableText, IHighlights, NativeEvent, SelectableTextProps } from './demo/SelectableText'
~~~~~~~~~~~
node_modules/@alentoma/react-native-selectable-text/index.ts:1:57 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
1 export { SelectableText as SelectableText, IHighlights, NativeEvent, SelectableTextProps } from './demo/SelectableText'
~~~~~~~~~~~
node_modules/@alentoma/react-native-selectable-text/index.ts:1:70 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
1 export { SelectableText as SelectableText, IHighlights, NativeEvent, SelectableTextProps } from './demo/SelectableText'
~~~~~~~~~~~~~~~~~~~
Temporarily I'm adding a // @ts-nocheck to the SelectableText.tsx file and export some types and patching it
// yarn patch-package @alentoma/react-native-selectable-text
diff --git a/node_modules/@alentoma/react-native-selectable-text/demo/SelectableText.tsx b/node_modules/@alentoma/react-native-selectable-text/demo/SelectableText.tsx
index a2f714a..8d3aed9 100644
--- a/node_modules/@alentoma/react-native-selectable-text/demo/SelectableText.tsx
+++ b/node_modules/@alentoma/react-native-selectable-text/demo/SelectableText.tsx
@@ -1,3 +1,4 @@
+// @ts-nocheck
import React, { ReactNode } from 'react'
import { Text, requireNativeComponent, Platform, TextStyle, StyleProp, TextProps, TextInputProps, ColorValue } from 'react-native'
import { v4 } from 'uuid'
diff --git a/node_modules/@alentoma/react-native-selectable-text/index.ts b/node_modules/@alentoma/react-native-selectable-text/index.ts
index f271a6d..0438def 100644
--- a/node_modules/@alentoma/react-native-selectable-text/index.ts
+++ b/node_modules/@alentoma/react-native-selectable-text/index.ts
@@ -1 +1,2 @@
-export { SelectableText as SelectableText, IHighlights, NativeEvent, SelectableTextProps } from './demo/SelectableText'
+export { SelectableText as SelectableText } from './demo/SelectableText'
+export type { IHighlights, NativeEvent, SelectableTextProps } from './demo/SelectableText'
Hmm, yes tsc should complaine about this as it is really not optimized to be used with tsc