opensearch-project / opensearch-js

Node.js Client for OpenSearch
https://opensearch.org/docs/latest/clients/javascript/
Apache License 2.0
179 stars 118 forks source link

[BUG] MappingGenericProperty should have optional fields #703

Open alex-at-cascade opened 5 months ago

alex-at-cascade commented 5 months ago

What is the bug?

The type definition for MappingGenericProperty has mandatory fields

How can one reproduce the bug?

Try to compile this code:

import { MappingTypeMapping } from "@opensearch-project/opensearch/api/types";
const x = { foo: { type: "date" } };
const f = (p: MappingTypeMapping["properties"]) => p;
f(x);

An error is reported:

TSError: ⨯ Unable to compile TypeScript:
bug.ts:4:3 - error TS2345: Argument of type '{ foo: { type: string; }; }' is not assignable to parameter of type 'Record<string, MappingProperty>'.
  Property 'foo' is incompatible with index signature.
    Type '{ type: string; }' is not assignable to type 'MappingProperty'.
      Type '{ type: string; }' is missing the following properties from type 'MappingGenericProperty': analyzer, boost, fielddata, ignore_malformed, and 7 more.

4 f(x);

What is the expected behavior?

It should compile ok.

What is your host/environment?

node 18, typescript 5.2.2

Do you have any screenshots?

N/A

Do you have any additional context?

It appears that the other similar types do have optional fields, but the "generic" version is the odd one out.

nhtruong commented 5 months ago

@alex-at-cascade would you like to take a crack at fixing this? :)

alex-at-cascade commented 5 months ago

Sure thing! I'll ramp up on the contribution guidelines.