From 202bdcf741888af1c01dfa97c0a6242f73571da2 Mon Sep 17 00:00:00 2001 From: Enguerran Weiss Date: Wed, 6 Sep 2023 15:28:32 +0200 Subject: [PATCH] fix wrong type on target / currentTarget on SelectNext --- src/SelectNext.tsx | 17 +++++++++++++++-- test/types/Select.tsx | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/SelectNext.tsx b/src/SelectNext.tsx index b1a4e5365..05755359c 100644 --- a/src/SelectNext.tsx +++ b/src/SelectNext.tsx @@ -34,11 +34,24 @@ export type SelectProps = { value?: Options[number]["value"]; onChange?: ( e: Omit, "target" | "currentTarget"> & { - target: Omit, "value"> & { + target: Omit & { value: Options[number]["value"]; + selectedOptions: HTMLCollectionOf< + Omit & { + value: Options[number]["value"]; + } + >; }; - currentTarget: Omit, "value"> & { + currentTarget: Omit< + EventTarget & HTMLSelectElement, + "value" | "selectedOptions" + > & { value: Options[number]["value"]; + selectedOptions: HTMLCollectionOf< + Omit & { + value: Options[number]["value"]; + } + >; }; } ) => void; diff --git a/test/types/Select.tsx b/test/types/Select.tsx index 0ab770ec4..c960beacb 100644 --- a/test/types/Select.tsx +++ b/test/types/Select.tsx @@ -262,3 +262,37 @@ import { assert, type Equals } from "tsafe"; }} />; } + +{ + const dogOrCatOptions = [ + { + value: "dog", + label: "Dog" + }, + { + value: "cat", + label: "Cat" + } + ] as const; + + type DogOrCat = typeof dogOrCatOptions[number]["value"]; + type SelectTarget = Omit & { + value: DogOrCat; + selectedOptions: HTMLCollectionOf & { value: DogOrCat }>; + }; +