From 38f7cf6a7e75113582f697f7b9956d01fa857275 Mon Sep 17 00:00:00 2001 From: Wes Souza Date: Wed, 27 Jul 2022 19:21:08 -0400 Subject: [PATCH] fix(select): fix type issues with onChange --- src/Select/Select.tsx | 5 ++++- src/Select/Select.types.ts | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Select/Select.tsx b/src/Select/Select.tsx index 16a0b65d..fae7c642 100644 --- a/src/Select/Select.tsx +++ b/src/Select/Select.tsx @@ -434,7 +434,10 @@ function SelectInner( return; } - onChange?.(event, nextSelection as unknown as SelectOption); + onChange?.( + event as unknown as SelectChangeEvent, + nextSelection as unknown as SelectOption + ); setValueState(nextSelection.value); displayNode.current?.focus(); }, diff --git a/src/Select/Select.types.ts b/src/Select/Select.types.ts index 029d73b7..934a27a3 100644 --- a/src/Select/Select.types.ts +++ b/src/Select/Select.types.ts @@ -1,12 +1,19 @@ import React from 'react'; +type SelectChangeEventTargetValue = { value: T; name: string | undefined }; + export type SelectChangeEvent = - | (React.MouseEvent & { - target: { - value: { value: T; name: string | undefined }; - }; + | (Omit, 'target'> & { + target: Omit< + React.ChangeEvent['target'], + 'name' | 'value' + > & + SelectChangeEventTargetValue; }) - | React.ChangeEvent; + | (Omit & { + target: Omit & + SelectChangeEventTargetValue; + }); export type SelectOption = { label: string;