Skip to content

Commit e0046f6

Browse files
committed
chore: fix typescript issues
1 parent b2c5213 commit e0046f6

File tree

23 files changed

+183
-170
lines changed

23 files changed

+183
-170
lines changed

example/src/Examples/DialogExample.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Platform, StyleSheet } from 'react-native';
33

44
import { Button } from 'react-native-paper';
55

6+
import { useExampleTheme } from '..';
67
import {
78
DialogWithCustomColors,
89
DialogWithDismissableBackButton,
@@ -12,7 +13,6 @@ import {
1213
DialogWithRadioBtns,
1314
UndismissableDialog,
1415
} from './Dialogs';
15-
import { useExampleTheme } from '..';
1616
import ScreenWrapper from '../ScreenWrapper';
1717

1818
type ButtonVisibility = {

src/components/Appbar/Appbar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
modeAppbarHeight,
2020
renderAppbarContent,
2121
filterAppbarActions,
22+
AppbarChildProps,
2223
} from './utils';
2324
import { useInternalTheme } from '../../core/theming';
2425
import type { MD3Elevation, ThemeProp } from '../../types';
@@ -210,7 +211,7 @@ const Appbar = ({
210211
let rightItemsCount = 0;
211212

212213
React.Children.forEach(children, (child) => {
213-
if (React.isValidElement(child)) {
214+
if (React.isValidElement<AppbarChildProps>(child)) {
214215
const isLeading = child.props.isLeading === true;
215216

216217
if (child.type === AppbarContent) {

src/components/Appbar/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import type { InternalTheme, ThemeProp } from '../../types';
88

99
export type AppbarModes = 'small' | 'medium' | 'large' | 'center-aligned';
1010

11+
export type AppbarChildProps = {
12+
isLeading?: boolean;
13+
color: string;
14+
style?: StyleProp<ViewStyle>;
15+
};
16+
1117
const borderStyleProperties = [
1218
'borderRadius',
1319
'borderTopLeftRadius',
@@ -124,7 +130,7 @@ export const filterAppbarActions = (
124130
isLeading = false
125131
) => {
126132
return React.Children.toArray(children).filter((child) => {
127-
if (!React.isValidElement(child)) return false;
133+
if (!React.isValidElement<AppbarChildProps>(child)) return false;
128134
return isLeading ? child.props.isLeading : !child.props.isLeading;
129135
});
130136
};
@@ -151,7 +157,7 @@ export const renderAppbarContent = ({
151157
)
152158
.map((child, i) => {
153159
if (
154-
!React.isValidElement(child) ||
160+
!React.isValidElement<AppbarChildProps>(child) ||
155161
![
156162
'Appbar.Content',
157163
'Appbar.Action',

src/components/BottomNavigation/BottomNavigation.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,9 @@ const BottomNavigation = <Route extends BaseRoute>({
441441
// eslint-disable-next-line react-hooks/exhaustive-deps
442442
}, []);
443443

444-
const prevNavigationState = React.useRef<NavigationState<Route>>();
444+
const prevNavigationState = React.useRef<NavigationState<Route> | undefined>(
445+
undefined
446+
);
445447

446448
React.useEffect(() => {
447449
// Reset offsets of previous and current tabs before animation

src/components/Card/CardActions.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
33

44
import type { ThemeProp } from 'src/types';
55

6+
import { CardActionChildProps } from './utils';
67
import { useInternalTheme } from '../../core/theming';
78

89
export type Props = React.ComponentPropsWithRef<typeof View> & {
@@ -45,7 +46,7 @@ const CardActions = ({ theme, style, children, ...rest }: Props) => {
4546
return (
4647
<View {...rest} style={containerStyle}>
4748
{React.Children.map(children, (child, index) => {
48-
if (!React.isValidElement(child)) {
49+
if (!React.isValidElement<CardActionChildProps>(child)) {
4950
return child;
5051
}
5152

src/components/Card/utils.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ViewStyle } from 'react-native';
1+
import type { StyleProp, ViewStyle } from 'react-native';
22

33
import color from 'color';
44

@@ -12,6 +12,12 @@ type BorderRadiusStyles = Pick<
1212
Extract<keyof ViewStyle, `border${string}Radius`>
1313
>;
1414

15+
export type CardActionChildProps = {
16+
compact?: boolean;
17+
mode?: string;
18+
style?: StyleProp<ViewStyle>;
19+
};
20+
1521
export const getCardCoverStyle = ({
1622
theme,
1723
index,

src/components/Chip/Chip.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616

1717
import useLatestCallback from 'use-latest-callback';
1818

19-
import { getChipColors } from './helpers';
19+
import { ChipAvatarProps, getChipColors } from './helpers';
2020
import { useInternalTheme } from '../../core/theming';
2121
import { white } from '../../styles/themes/v2/colors';
2222
import type { $Omit, EllipsizeProp, ThemeProp } from '../../types';
@@ -339,8 +339,8 @@ const Chip = ({
339339
disabled && { opacity },
340340
]}
341341
>
342-
{React.isValidElement(avatar)
343-
? React.cloneElement(avatar as React.ReactElement<any>, {
342+
{React.isValidElement<ChipAvatarProps>(avatar)
343+
? React.cloneElement(avatar, {
344344
style: [styles.avatar, avatar.props.style],
345345
})
346346
: avatar}

src/components/Chip/helpers.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import type { ColorValue } from 'react-native';
1+
import type { ColorValue, StyleProp, ViewStyle } from 'react-native';
22

33
import color from 'color';
44

55
import { black, white } from '../../styles/themes/v2/colors';
66
import type { InternalTheme } from '../../types';
77

8+
export type ChipAvatarProps = {
9+
style?: StyleProp<ViewStyle>;
10+
};
11+
812
type BaseProps = {
913
theme: InternalTheme;
1014
isOutlined: boolean;

src/components/Dialog/Dialog.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { useInternalTheme } from '../../core/theming';
1818
import overlay from '../../styles/overlay';
1919
import type { ThemeProp } from '../../types';
2020
import Modal from '../Modal';
21+
import { DialogChildProps } from './utils';
2122

2223
export type Props = {
2324
/**
@@ -138,20 +139,20 @@ const Dialog = ({
138139
.filter((child) => child != null && typeof child !== 'boolean')
139140
.map((child, i) => {
140141
if (isV3) {
141-
if (i === 0 && React.isValidElement(child)) {
142-
return React.cloneElement(child as React.ReactElement<any>, {
142+
if (i === 0 && React.isValidElement<DialogChildProps>(child)) {
143+
return React.cloneElement(child, {
143144
style: [{ marginTop: 24 }, child.props.style],
144145
});
145146
}
146147
}
147148

148149
if (
149150
i === 0 &&
150-
React.isValidElement(child) &&
151+
React.isValidElement<DialogChildProps>(child) &&
151152
child.type === DialogContent
152153
) {
153154
// Dialog content is the first item, so we add a top padding
154-
return React.cloneElement(child as React.ReactElement<any>, {
155+
return React.cloneElement(child, {
155156
style: [{ paddingTop: 24 }, child.props.style],
156157
});
157158
}

src/components/Dialog/DialogActions.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native';
33

44
import type { ThemeProp } from 'src/types';
55

6+
import { DialogActionChildProps } from './utils';
67
import { useInternalTheme } from '../../core/theming';
78

89
export type Props = React.ComponentPropsWithRef<typeof View> & {
@@ -55,8 +56,8 @@ const DialogActions = (props: Props) => {
5556
style={[isV3 ? styles.v3Container : styles.container, props.style]}
5657
>
5758
{React.Children.map(props.children, (child, i) =>
58-
React.isValidElement(child)
59-
? React.cloneElement(child as React.ReactElement<any>, {
59+
React.isValidElement<DialogActionChildProps>(child)
60+
? React.cloneElement(child, {
6061
compact: true,
6162
uppercase: !isV3,
6263
style: [

0 commit comments

Comments
 (0)