Skip to content

Commit

Permalink
Improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
vhande committed Nov 22, 2024
1 parent 5dba2ce commit d092d8b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Inline } from '@/ui/Inline';
import { Stack } from '@/ui/Stack';
import { Text, TextVariants } from '@/ui/Text';
import { getGlobalBorderRadius, getValueFromTheme } from '@/ui/theme';
import { Typeahead } from '@/ui/Typeahead';
import { Typeahead, TypeaheadElement } from '@/ui/Typeahead';
import { getUniqueLabels } from '@/utils/getUniqueLabels';

type OrganizerLabelProps = {
Expand All @@ -29,7 +29,7 @@ type OrganizerLabelProps = {

export const OrganizerLabels = ({ organizer }: OrganizerLabelProps) => {
const { t } = useTranslation();
const ref = useRef(null);
const ref = useRef<TypeaheadElement<Label>>(null);
const router = useRouter();
const [query, setQuery] = useState('');
// @ts-expect-error
Expand Down
4 changes: 2 additions & 2 deletions src/pages/steps/AdditionalInformationStep/LabelsStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Inline } from '@/ui/Inline';
import { getStackProps, Stack, StackProps } from '@/ui/Stack';
import { Text, TextVariants } from '@/ui/Text';
import { getGlobalBorderRadius, getValueFromTheme } from '@/ui/theme';
import { Typeahead } from '@/ui/Typeahead';
import { Typeahead, TypeaheadElement } from '@/ui/Typeahead';
import { getUniqueLabels } from '@/utils/getUniqueLabels';

type LabelsStepProps = StackProps & TabContentProps;
Expand All @@ -44,7 +44,7 @@ function LabelsStep({
// @ts-expect-error
const entity: Offer | Organizer | undefined = getEntityByIdQuery.data;

const ref = useRef(null);
const ref = useRef<TypeaheadElement<Label>>(null);

const [query, setQuery] = useState('');
// @ts-expect-error
Expand Down
7 changes: 5 additions & 2 deletions src/ui/Typeahead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ type NewEntry = {
label: string;
};

export type TypeaheadElement<T extends TypeaheadModel = TypeaheadModel> =
BootstrapTypeahead<T>;

const isNewEntry = (value: any): value is NewEntry => {
return !!value?.customOption;
};
Expand Down Expand Up @@ -65,7 +68,7 @@ const TypeaheadInner = <T extends TypeaheadModel>(
isLoading,
...props
}: Props<T>,
ref: ForwardedRef<HTMLInputElement>,
ref: ForwardedRef<BootstrapTypeahead<T>>,
) => {
const { t } = useTranslation();

Expand Down Expand Up @@ -164,7 +167,7 @@ const TypeaheadInner = <T extends TypeaheadModel>(
};

const Typeahead = forwardRef(TypeaheadInner) as <T extends TypeaheadModel>(
props: Props<T> & { ref?: ForwardedRef<HTMLInputElement> },
props: Props<T> & { ref?: ForwardedRef<BootstrapTypeahead<T>> },
) => ReturnType<typeof TypeaheadInner<T>>;

export type { NewEntry };
Expand Down

0 comments on commit d092d8b

Please sign in to comment.