Skip to content

TypeScript Error #1715

@sarunluitel

Description

@sarunluitel

🐛 Bug Report

using a readonly string[] in where string[] is expected gives error. just Using filter_path as an example, I have an array of common values stored. These will never change so wanted to follow best practice to use Object.freeze(). This changed the datatype from string[] to readonly string[].

Filing this as bugreport to request elasticsearch to add readonly values in such case. Let me know if this is omitted by design and may cause errors that I may not know of.

To Reproduce

Steps to reproduce the behavior:

Paste the results here:

const ELASTICSEARCH_COMMON_FILTER_PATH = Object.freeze(['hits.total.value', 'hits.hits._source', 'hits.hits._score']);

const elasticSearchKeywordQuery: estypes.SearchRequest = {
    index: ELASTICSEARCH_INDEX,
    _source: Object.keys(getProperties),
    filter_path: ELASTICSEARCH_COMMON_FILTER_PATH, // Here is the Error
    query: {...
      // rest of the query is not relevant to this issue

Error Message

(property) SpecUtilsCommonQueryParameters.filter_path?: string | string[]
Type 'readonly string[]' is not assignable to type 'string | string[]'.ts(2322)
types.d.ts(15093, 5): The expected type comes from property 'filter_path' which is declared here on type 'SearchRequest'

Expected behavior

readonly datatypeX should work everywhere datatypeX works.

Your Environment

  • node version: 16
  • @elastic/elasticsearch version: >=8.2.1
  • os: Mac,

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions