From d830a6f828e04454873056370679eea28c49365f Mon Sep 17 00:00:00 2001 From: Daniel Sallai Date: Mon, 1 Mar 2021 19:11:07 +0100 Subject: [PATCH] fix: enable autocomplete to use const type --- .../material-ui/src/useAutocomplete/useAutocomplete.d.ts | 2 +- .../src/useAutocomplete/useAutocomplete.spec.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/material-ui/src/useAutocomplete/useAutocomplete.d.ts b/packages/material-ui/src/useAutocomplete/useAutocomplete.d.ts index 693b529f884e40..e4e40085fb34d7 100644 --- a/packages/material-ui/src/useAutocomplete/useAutocomplete.d.ts +++ b/packages/material-ui/src/useAutocomplete/useAutocomplete.d.ts @@ -228,7 +228,7 @@ export interface UseAutocompleteProps< /** * Array of options. */ - options: T[]; + options: ReadonlyArray; /** * If `true`, the input's text is selected on focus. * It helps the user clear the selected value. diff --git a/packages/material-ui/src/useAutocomplete/useAutocomplete.spec.ts b/packages/material-ui/src/useAutocomplete/useAutocomplete.spec.ts index 955335d4974dd2..f31398b6a6fa87 100644 --- a/packages/material-ui/src/useAutocomplete/useAutocomplete.spec.ts +++ b/packages/material-ui/src/useAutocomplete/useAutocomplete.spec.ts @@ -104,6 +104,14 @@ function Component() { onChange(event, value: Person[]) {}, }); + // options accepts const and value has correct type + useAutocomplete({ + options: ['1', '2', '3'] as const, + onChange(event, value) { + expectType<'1' | '2' | '3' | null, typeof value>(value); + }, + }); + // Disable clearable useAutocomplete({