From 888979eb80844d89b12e75e4d04b282c9a6a04df Mon Sep 17 00:00:00 2001 From: dej611 Date: Tue, 23 Jun 2020 15:01:01 +0200 Subject: [PATCH] Fix type checker issues --- .../components/settings/advanced_settings_form.tsx | 12 ++++++++---- .../public/components/settings/settings.test.tsx | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/graph/public/components/settings/advanced_settings_form.tsx b/x-pack/plugins/graph/public/components/settings/advanced_settings_form.tsx index 592c05fc20a50..51f802edec9d0 100644 --- a/x-pack/plugins/graph/public/components/settings/advanced_settings_form.tsx +++ b/x-pack/plugins/graph/public/components/settings/advanced_settings_form.tsx @@ -38,11 +38,15 @@ export function AdvancedSettingsForm({ } function getNumberUpdater>(key: K) { - return function ({ target: { valueAsNumber } }: { target: { valueAsNumber: number | '' } }) { + return function ({ + target: { valueAsNumber, value }, + }: { + target: { valueAsNumber: number; value: string }; + }) { // if the value is valid, then update the central store, otherwise only the local store - if (valueAsNumber === '' || Number.isNaN(valueAsNumber)) { + if (Number.isNaN(valueAsNumber)) { // localstate update - return updateFormState({ ...formState, [key]: valueAsNumber }); + return updateFormState({ ...formState, [key]: value }); } // do not worry about local store here, the useEffect will pick that up and sync it updateSetting(key, valueAsNumber); @@ -167,7 +171,7 @@ export function AdvancedSettingsForm({ defaultMessage: 'Max number of documents in a sample that can contain the same value for the', })}{' '} - {formState.sampleDiversityField!.name}{' '} + {formState.sampleDiversityField.name}{' '} {i18n.translate( 'xpack.graph.settings.advancedSettings.maxValuesInputHelpText.fieldText', { diff --git a/x-pack/plugins/graph/public/components/settings/settings.test.tsx b/x-pack/plugins/graph/public/components/settings/settings.test.tsx index 67170026818c2..1efaead002b52 100644 --- a/x-pack/plugins/graph/public/components/settings/settings.test.tsx +++ b/x-pack/plugins/graph/public/components/settings/settings.test.tsx @@ -181,7 +181,7 @@ describe('settings', () => { it('should let the user edit and empty the field to input a new number', () => { act(() => { input('Sample size').prop('onChange')!({ - target: { valueAsNumber: '' }, + target: { value: '', valueAsNumber: NaN }, } as React.ChangeEvent); }); // Central state should not be called @@ -189,7 +189,7 @@ describe('settings', () => { updateSettings( expect.objectContaining({ timeoutMillis: 10000, - sampleSize: '', + sampleSize: NaN, }) ) );