elasticsearch-js icon indicating copy to clipboard operation
elasticsearch-js copied to clipboard

enum and/or type guard for QueryDslTextQueryType

Open y-nk opened this issue 5 months ago • 1 comments

🚀 Feature Proposal

We have a usecase where we receive/produce string as a type, which should be typed as QueryDslTextQueryType. I would like to have a way in this library (as single source of truth) to produce a QueryDslTextQueryType from a string.

Motivation

It's much better if the guard is produced and maintained tightly with this library.

Example

enum QueryDslTextQueryType {
  // the values of QueryDslTextQueryType union type
}

function isQueryDslTextQueryType(arg: any): arg is QueryDslTextQueryType {
  return Object.values(QueryDslTextQueryType).includes(arg)
}

y-nk avatar Jan 22 '24 04:01 y-nk