Vue on WebStorm2023.1 exhibits a type inference issue with Promise.all in TypeScript

While the code works perfectly in the ts file and resolves the variable first to the string type, things get a bit complicated when trying to implement it under Vue3's Composition API. The types end up being merged, forcing me to specify the type manually.

What steps do I need to take to ensure it is recognized correctly even in Vue files?

TypeScript version: 5.0.4

// in .ts file
// type () => Promise<string>
const fun1 = () => Promise.resolve('A')
const fun2 = () => Promise.resolve([1])
const b = 1 + 1 === 2
Promise.all([fun1(), b ? fun2() : null]).then((res) => {
  // res type [string, number[] | null]

  // string
  const first = res[0]

  // number[]|null
  const second = res[1]
})
// in .vue file
<script setup>
// type () => Promise<Awaited<string>>
const fun1 = () => Promise.resolve('A')
const fun2 = () => Promise.resolve([1])
const b = 1 + 1 === 2
Promise.all([fun1(), b ? fun2() : null]).then((res) => {
  // res type Awaited<string | number[] | null>[]

  // type string|number[]|null
  const first = res[0]

  // type string|number[]|null
  const second = res[1]
})
</script>

Answer №1

The upcoming release of WebStorm 2023.2 will address this issue. You can give it a try by downloading the Early Access Program (EAP) version available now. For more details, check out the latest announcement here:

I personally have tested the fix in the most recent EAP build and it appears to be working well based on my experience. https://i.sstatic.net/ZnXqi.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Grunt Typescript is encountering difficulty locating the angular core module

Question Why is my Grunt Typescript compiler unable to locate the angular core? I suspect it's due to the paths, causing the compiler to not find the libraries in the node_modules directory. Error typescript/add.component.ts(1,25): error TS23 ...

Guide to implementing a Page Object Model for improved debugging of Protractor tests

Introduction I am on a mission to streamline my e2e testing code using the Page Object Model for easier maintenance and debugging. My Approach When embarking on creating end-to-end tests with Protractor, I follow these steps to implement the Page Object ...

Creating specific data types in Vue.js

Is it possible to create custom prop types with extended validation for Vue.js props? In the following example, we have a prop called background that is currently of type Object. I would like to change this to a custom prop type called Image. The Image pr ...

Discovering new bugs in VSCode Playwright Tests but failing to see any progress

This morning, everything was running smoothly with debugging tests. However, after a forced reboot, I encountered an issue where it seems like the debugger is running, but nothing actually happens. This has happened before, but usually resolves itself. Unf ...

In order to use the serve command, it is necessary to run it within an Angular project. However, if a project definition cannot be located

An error occurred while running the ng serve command: C:\Mysystem\Programs\myfwms>ng serve The serve command needs to be executed within an Angular project, but a project definition could not be found. I encounter this error when ...

Resolved error: Angular 'title' identifier is undefined. The 'Movie[]' array does not have this member

Attempting to fetch data from the backend using Angular services. After reading the Angular docs, it was mentioned that interfaces should be used when sending requests somewhere It should look something like this: return this.http.get<Movie[]>(th ...

Exploring methods to retrieve data from an array in a Vue store through Getters

I am currently facing an issue where I am attempting to include an argument within getters in order to retrieve the ID of the permissions, but unfortunately it is not returning any results. ////STATE state: { permissions: [ {id: 1, name: 'Crea ...

Error: Invalid connection string for ELF Lambda detected

Having an issue with a lambda function that connects to a remote MongoDB on an EC2 instance using TypeScript. While I can connect to the database locally, there is an ELF error when running in lambda. It seems to be related to mismatched binaries of npm pa ...

Integrate multiple components in Vue

I'm currently working on a project utilizing ElementUI Tabs without .vue files, using only HTML and JS. My goal is to dynamically open new tabs and populate them with HTML content when the user interacts with the menu items, similar to how I have done ...

What are the best practices for modifying data property values in Vuejs?

I'm just starting out with Vue.js and I'm having some trouble understanding the reactivity system. In the code below, I am attempting to change the initial value of a variable in the data property using a method. <script> name: "OrderDet ...

Tips for preventing the creation of .d.ts.map files while using tsc to exclusively generate declaration files

When I create a build using tsup, I encounter numerous errors with the dts option. The official tsup documentation also mentions that typescript declarations generated by tools other than tsc may not be perfect. As a result, I have decided to use tsc for ...

Bidirectional data binding in Angular 2 allows for communication between parent components and directives

Update: Experimenting with Angular2 Beta, I am working on incorporating an "editor" component template that includes a directive wrapping the Ace editor. In this scenario, the "editor" component acts as the parent of the Ace wrapper directive, and my goal ...

Understanding how to handle prop types in a React application using Typescript

My current task involves using the react-google-maps library to integrate Google Maps API into my project. The documentation specifies a certain way to set up the maps component: const GoogleMapComponent: React.ComponentClass<{}> = compose( with ...

Can you explain how to specify individual keys in an object literal in TypeScript?

So I've been working with this data structure export interface StoreData { msdb: {[tableName: string]: List<StoreModel>}; } However, I'm looking to restrict and enable auto-completion for specific string values in my tableName field. ...

What is the best way to showcase several images using Sweet Alert 2?

In the process of developing my Angular 2 application, I have incorporated sweet alert 2 into certain sections. I am looking to showcase multiple images (a minimum of two) at the same time in the pop-up. Does anyone have any suggestions on how to achieve ...

The React Native blob or file seems to be encountering trouble in reaching the server

I'm in a tough spot here. I can't figure out what's going wrong. My goal is to send a file using the expo-image-picker component to the server. The form gets sent, but the image doesn't. When I use the fetch command, I immediately get a ...

Depicting a potential value within Typescript

Coming from a background of working with functional languages that utilize monadic constructs like Option or Optional, I have noticed libraries such as fp-ts that provide these features in TypeScript/JavaScript. However, I am curious to understand how deve ...

Definition of composed types in TypeScript generics

I'm curious if there is a functional distinction between the two TypeScript type declarations below: object: Observable<number> | Observable<number[]> object: Observable<number | number[]> If there is a difference, what are the ...

Create a customizable feature for PrimeVue Splitter that allows for dynamic adjustments of panel sizes in real

I've implemented PrimeVue Splitter in conjunction with Vue3 and the composition API. My goal is to create dynamic panel sizes that can be reverted back to their original sizes when a button is clicked. This is my current setup: <button @click=&quo ...

What is the best way to modify a single item within a v-for loop in Vue.js 3?

I am attempting to achieve the following: <tr v-for="item in items" :key='item'> <td v-for="field in fields" :key='field'> {{ item[field.toLowerCase()] }} </td> </tr> It seems that ...