# How to make WebStorm / TypeScript completion work?

**URL:** <https://discuss.elastic.co/t/how-to-make-webstorm-typescript-completion-work/290222>\
**Category:** Elasticsearch\
**Created:** [November 25, 2021, 10:09pm UTC](https://discuss.elastic.co/t/how-to-make-webstorm-typescript-completion-work/290222 "2021-11-25T22:09:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![davestewart](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davestewart/32/97621_2.png) [@davestewart](https://discuss.elastic.co/u/davestewart)\
**Post date:** [November 25, 2021, 10:09pm UTC](https://discuss.elastic.co/t/how-to-make-webstorm-typescript-completion-work/290222/1 "2021-11-25T22:09:09Z")

</div>

Hi there,

I'm pretty new to Elastic, been using it on and off for about a year, using the JavaScript client.

I finally seem to be at the stage where I understand how to build complex queries, bool, match\_phrase\_prefix, ids, etc.

However, it's still hard work to remember the exact syntax for each, so my approach is generally:

- build the query in Kibana using its autocomplete
- wrap the code in a helper function
- compose helper function outputs to build queries

However, with either raw POJOs or using the helpers there's not much support in my IDE.

I see that it is possible to get some kind of completion using TypeScript:

> **[TypeScript support | Elasticsearch JavaScript Client \[7.16\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/typescript.html)**

I have also installed the global types in WebStorm:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/9/99d928b4ca39a5198b9b94fd233f564f86f54869.png)

But completion seems to bottom out at the query stage:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/6/565d0a1cc4e17e1e6799960e4b0d0902161ed038.png)

Before I went looking for TS support, I had a play with building some type support + helpers, and it worked exactly as I hoped it could:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/7/5/75d5c7ee5613d4672788c850e6c13b3b519f7a4a.png)

I could go forward from here and build out TS support for the small subset of features I use, but I figure this is what the Elastic TypeScript package should be doing, no?

I've attempted to import and set the definitions in `@elastic/elasticsearch/api` in my `tsconfig.json`'s `typeRoots` but no luck:

```json
    "typeRoots": [
      "node_modules/@elastic/elasticsearch",
    ]

```

![image](https://us1.discourse-cdn.com/elastic/original/3X/5/7/57c68adfffd48399b10f68a37370fc1098d01893.png)

My TS knowledge is pretty good (write and use generics, etc) but there are gaps (this possibly being one!).

Anyway... if you've read through all that, well done, and... what should I be doing to get both completion and type safety / warnings when building queries?

Thanks.  
Dave

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 23, 2021, 10:09pm UTC](https://discuss.elastic.co/t/how-to-make-webstorm-typescript-completion-work/290222/2 "2021-12-23T22:09:50Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
