From 6073960999cf17fb65e67723a511673357c002ca Mon Sep 17 00:00:00 2001 From: alex-at-cascade Date: Mon, 5 Feb 2024 08:25:03 -0800 Subject: [PATCH] Make optional fields optional in `MappingGenericProperty` (#703) Signed-off-by: alex-at-cascade --- CHANGELOG.md | 1 + api/types.d.ts | 22 +++++++++++----------- test/types/types.test-d.ts | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 test/types/types.test-d.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 1354047c3..1a56322b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Deprecated ### Removed ### Fixed +- Make optional fields optional in `MappingGenericProperty` ([708](https://github.com/opensearch-project/opensearch-js/pull/708)) ### Security ## [2.5.0] diff --git a/api/types.d.ts b/api/types.d.ts index 6628ce5da..a5be4da5a 100644 --- a/api/types.d.ts +++ b/api/types.d.ts @@ -3907,17 +3907,17 @@ export interface MappingFloatRangeProperty extends MappingRangePropertyBase { } export interface MappingGenericProperty extends MappingDocValuesPropertyBase { - analyzer: string; - boost: double; - fielddata: IndicesStringFielddata; - ignore_malformed: boolean; - index: boolean; - index_options: MappingIndexOptions; - norms: boolean; - null_value: string; - position_increment_gap: integer; - search_analyzer: string; - term_vector: MappingTermVectorOption; + analyzer?: string; + boost?: double; + fielddata?: IndicesStringFielddata; + ignore_malformed?: boolean; + index?: boolean; + index_options?: MappingIndexOptions; + norms?: boolean; + null_value?: string; + position_increment_gap?: integer; + search_analyzer?: string; + term_vector?: MappingTermVectorOption; type: string; } diff --git a/test/types/types.test-d.ts b/test/types/types.test-d.ts new file mode 100644 index 000000000..6337ac701 --- /dev/null +++ b/test/types/types.test-d.ts @@ -0,0 +1,20 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + */ + +import { expectAssignable } from 'tsd'; +import { MappingProperty } from '../../api/types'; + +// https://github.com/opensearch-project/opensearch-js/issues/703 +// only manifested when value is in a variable, so the following would *not* catch it: +// +// expectAssignable({ type: 'date' }); + +const x = { type: 'date' }; +expectAssignable(x);