From d88ae953170c1237f456d8f96b665bcb2506c481 Mon Sep 17 00:00:00 2001 From: Abel Toledano Date: Thu, 20 Jul 2023 15:25:23 +0200 Subject: [PATCH] fix(Row): improve onPress/to/href types --- src/__type_tests__/list-type-test.tsx | 22 +++++++++++++--------- src/list.tsx | 12 ++++++------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/__type_tests__/list-type-test.tsx b/src/__type_tests__/list-type-test.tsx index 26fdb4e243..4a98f1a1a7 100644 --- a/src/__type_tests__/list-type-test.tsx +++ b/src/__type_tests__/list-type-test.tsx @@ -1,7 +1,7 @@ import * as React from 'react'; import {RowList, BoxedRowList, BoxedRow, Row} from '../list'; -const v = true; +const v = true as boolean; // @ts-expect-error - missing children ; @@ -22,40 +22,44 @@ const v = true; {/* @ts-expect-error - missing props */} - {/* @ts-expect-error - children not allowed */} error - {/* OK - basic */} - {/* OK - to */} + {/* @ts-expect-error - newTab not allowed in to */} - {/* OK - href */} + {/* @ts-expect-error - fullPageOnWebView not allowed in href */} - {/* OK - onPress */} {}} /> + {}} trackingEvent={{name: 'something'}} /> {/* @ts-expect-error - fullPageOnWebView not allowed in onPress */} {}} fullPageOnWebView /> - {/* OK - switch */} - + {}} /> {/* OK - checkbox */} - + {}} /> {/* OK - radio */} + {}} /> + {/* @ts-expect-error - can't use trackingEvent without to/href/onPress */} + + + {} : undefined} /> + + ; diff --git a/src/list.tsx b/src/list.tsx index 2ad617b2fb..fe546debce 100644 --- a/src/list.tsx +++ b/src/list.tsx @@ -213,33 +213,33 @@ interface BasicRowContentProps extends CommonProps { } interface SwitchRowContentProps extends CommonProps { - onPress?: () => void; + onPress?: (() => void) | undefined; switch: ControlProps | undefined; } interface CheckboxRowContentProps extends CommonProps { - onPress?: () => void; + onPress?: (() => void) | undefined; checkbox: ControlProps | undefined; } interface RadioRowContentProps extends CommonProps { - onPress?: () => void; + onPress?: (() => void) | undefined; radioValue: string; } interface HrefRowContentProps extends CommonProps { trackingEvent?: TrackingEvent | ReadonlyArray; - href: string; + href: string | undefined; newTab?: boolean; right?: Right; } interface ToRowContentProps extends CommonProps { trackingEvent?: TrackingEvent | ReadonlyArray; - to: string; + to: string | undefined; fullPageOnWebView?: boolean; replace?: boolean; right?: Right; @@ -247,7 +247,7 @@ interface ToRowContentProps extends CommonProps { interface OnPressRowContentProps extends CommonProps { trackingEvent?: TrackingEvent | ReadonlyArray; - onPress: () => void; + onPress: (() => void) | undefined; right?: Right; }