Skip to content

Commit 3481fd9

Browse files
authored
fix: data type not being inferred correctly (#335)
* fix: data type not being inferred correctly * feat: remove deprecated prop-types
1 parent b3d7ba6 commit 3481fd9

File tree

3 files changed

+7
-64
lines changed

3 files changed

+7
-64
lines changed

examples/StarWarsMovieFinder/App.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Autocomplete from 'react-native-autocomplete-input';
22
import React, { useEffect, useState } from 'react';
3-
import { SWAPI, Movies, Movie, filterMovies } from './swapi';
3+
import { SWAPI, type Movies, filterMovies } from './swapi';
44
import { MovieDetails } from './MovieDetails';
55
import { Platform, StyleSheet, Text, TouchableOpacity, View, SafeAreaView } from 'react-native';
66

@@ -10,7 +10,7 @@ function StarWarsMovieFinder(): React.ReactElement {
1010
const queriedMovies = React.useMemo(() => filterMovies(allMovies, query), [allMovies, query]);
1111

1212
const [firstMovieSuggestion] = queriedMovies;
13-
const suggestions: Movies = React.useMemo(
13+
const suggestions = React.useMemo(
1414
() =>
1515
firstMovieSuggestion?.compareTitle(query)
1616
? [] // Close suggestion list in case movie title matches query
@@ -40,7 +40,7 @@ function StarWarsMovieFinder(): React.ReactElement {
4040
placeholder={placeholder}
4141
flatListProps={{
4242
keyboardShouldPersistTaps: 'always',
43-
keyExtractor: (movie: Movie) => movie.episodeId.toString(),
43+
keyExtractor: (movie) => movie.episodeId.toString(),
4444
renderItem: ({ item }) => (
4545
<TouchableOpacity onPress={() => setQuery(item.title)}>
4646
<Text style={styles.itemText}>{item.title}</Text>

packages/react-native-autocomplete-input/index.tsx

+4-58
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import React from 'react';
1+
import React, { ReactElement } from 'react';
22
import type {
33
FlatListProps,
44
TextInputProps,
55
StyleProp,
66
ViewStyle,
77
ListRenderItemInfo,
88
} from 'react-native';
9-
import PropTypes from 'prop-types';
109
import { FlatList, Platform, StyleSheet, Text, TextInput, View } from 'react-native';
11-
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
1210

1311
export type AutocompleteInputProps<Item> = TextInputProps & {
1412
containerStyle?: StyleProp<ViewStyle>;
@@ -87,7 +85,9 @@ export const AutocompleteInput = React.forwardRef(function AutocompleteInputComp
8785
)}
8886
</View>
8987
);
90-
});
88+
}) as <Item, Ref>(
89+
props: AutocompleteInputProps<Item> & { ref?: React.ForwardedRef<Ref> },
90+
) => ReactElement;
9191

9292
const border = {
9393
borderColor: '#b9b9b9',
@@ -148,57 +148,3 @@ const styles = StyleSheet.create({
148148
});
149149

150150
export default AutocompleteInput;
151-
152-
AutocompleteInput.propTypes = {
153-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
154-
// @ts-ignore
155-
...TextInput.propTypes,
156-
/**
157-
* These styles will be applied to the container which
158-
* surrounds the autocomplete component.
159-
*/
160-
containerStyle: ViewPropTypes ? ViewPropTypes.style : PropTypes.object,
161-
/**
162-
* Assign an array of data objects which should be
163-
* rendered in respect to the entered text.
164-
*/
165-
data: PropTypes.array,
166-
/**
167-
* Props which can be applied to result `FlatList`.
168-
*/
169-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
170-
// @ts-ignore
171-
flatListProps: FlatList.propTypes || PropTypes.object,
172-
/**
173-
* Set to `true` to hide the suggestion list.
174-
*/
175-
hideResults: PropTypes.bool,
176-
/**
177-
* These styles will be applied to the container which surrounds
178-
* the textInput component.
179-
*/
180-
inputContainerStyle: ViewPropTypes ? ViewPropTypes.style : PropTypes.object,
181-
/**
182-
* These style will be applied to the result list.
183-
*/
184-
listContainerStyle: ViewPropTypes ? ViewPropTypes.style : PropTypes.object,
185-
/**
186-
* `onShowResults` will be called when list is going to
187-
* show/hide results.
188-
*/
189-
onShowResults: PropTypes.func,
190-
/**
191-
* `onShowResults` will be called when list is going to
192-
* show/hide results.
193-
*/
194-
onStartShouldSetResponderCapture: PropTypes.func,
195-
/**
196-
* renders custom TextInput. All props passed to this function.
197-
*/
198-
renderTextInput: PropTypes.func,
199-
/**
200-
* renders custom result list. Can be used to replace FlatList.
201-
* All props passed to this function.
202-
*/
203-
renderResultList: PropTypes.func,
204-
};

packages/react-native-autocomplete-input/package.json

-3
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,5 @@
4040
"jest": "^29.4.3",
4141
"react": "18.3.1",
4242
"react-native": "0.76.5"
43-
},
44-
"dependencies": {
45-
"deprecated-react-native-prop-types": "^5.0.0"
4643
}
4744
}

0 commit comments

Comments
 (0)