Exploring the power of Vue3 with reactive nested objects and the inclusion of

It seems like I've encountered a bit of a challenge... Perhaps a bug in Vue3 with Typescript and the composition API, or maybe I'm missing something.

I'm facing an issue where I'm not getting any intellisense in my IDE (Webstorm) when I have an object that is typed as optional:

Here's a small example I've set up: In this scenario, you would expect to see "commentAuthor" suggested when accessing .comment, but unfortunately, I'm not getting this suggestion. However, if I specify in my interface that comment should not be optional, then I do get the correct intellisense. You can see what I mean in the image attached below

<template>
  <h2>This is a Vue 3 component!</h2>
  {{ test.post.comment.commentAuthor }}
</template>

<script lang="ts">
import { defineComponent, reactive } from "vue";

interface Comment {
  id: string;
  commentAuthor: string;
  topFriend?: {
    uid: string;
    name: string;
  };
}
interface Post {
  id: string;
  postContent: string;
  comment?: Comment;
}

export interface TestInterface {
  id: string;
  name: string;
  post: Post;
}

export default defineComponent({
  setup() {
    const test = reactive({
      id: "123",
      name: "John doe",
      post: {
        id: "333",
        postContent: "Lorem ipsum",
        comment: {
          id: "444",
          commentAuthor: "Jane Doe",
          topFriend: {
            uid: "555",
            name: "Donald Duck",
          },
        },
      },
    }) as TestInterface;

    return {
      test,
    };
  },
});
</script>

With optional prop in my interface With optional prop in my interface:

Without optional prop Without optional prop

Why is this happening? I believe it's common to have optional objects, so Vue should ideally handle this situation

Answer №1

This issue stems from the IDE malfunction, you can stay updated by visiting WEB-50101

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

What are the steps to customize the collapse and expand icons?

Having trouble changing the icon up and down when collapsing and expanding with the code below. <div class="attach-link"> <a href="javascript:void(0);" *ngIf="fileData.fileDataType.canAttach && !isFinancialEntity" (click) ...

Organizing folders and files for Nuxt query string parameters

What is the optimal structure for organizing files and folders to utilize URL query string parameters instead of regular parameters? For example: Using URL parameters: Folder organization: pages/ ---|comments/ ------|_id.vue This setup leads to the fol ...

What are the two different ways to declare a property?

I am trying to update my interface as shown below interface Student{ Name: String; age: Number; } However, instead of the current structure, I would like it to be like this interface Student{ Name: String; age | DOB: Number | Date; } This means t ...

Deactivate specific choices from a dynamically generated dropdown menu in Angular 8

I am working on a dynamic dropdown feature with multiple fields. By pressing the + button, a new row is generated. Users can add any number of rows. My challenge is to prevent users from selecting previously chosen values in the dropdown list. I have ma ...

Is it possible to eliminate the arrows from an input type while restricting the change to a specific component?

Is there a way to remove the arrows from my input field while still applying it only to the text fields within this component? <v-text-field class="inputPrice" type="number" v-model="$data._value" @change="send ...

Struggling with setting up Angular Material and SCSS configuration in my application -

Hey there, I encountered an error or warning while trying to launch my angular app. Here's the issue: ERROR in ./src/styles/styles.scss (./node_modules/@angular-devkit/build- angular/src/angular-cli-files/plugins/raw-css- loader.js!./n ...

Having trouble with routerLink in your custom library while using Angular 4?

In my Angular 4 project, I have developed a custom sidebar library and integrated it into the main project. My current issue is that I want to provide the option for users to "open in new tab/window" from the browser's context menu without having the ...

Prevent assigning values to rxjs observables recursively

I am seeking suggestions on how to enhance the code provided below. I will outline the issue and present my current solution, which I aim to refine. The code is written in Angular 4 (TS). herelistOfItems$: Observable<Array<Item>>; // Fetchin ...

React dynamic table

I've been experimenting with creating a dynamic table in React that allows users to add and delete rows. I need the data entered by the user to be saved, possibly using in-state management so that I can work with it later. Essentially, I'm looki ...

What is the best way to implement date range filtering in vue js?

Currently, I am delving into the realm of vue.js and experimenting with a filtering feature that involves date ranges. The process goes like this: initially filter by type, then proceed to filter by a specified date range, consisting of start and end dat ...

How can I receive live notifications for a document as soon as it is created?

My Angular app is connected to Cloud Firestore, and I've created a function in a service to retrieve a user's rating from the 'ratings' collection. Each rating is stored in this collection with the document ID being a combination of the ...

Manipulating a prop class from a child component in Vue

I am still in the process of learning Vue and there is something I am struggling with. I have a component called WS.vue that assigns a class to a div (active) when a checkbox is clicked. Currently, the click event works fine and changes the class for each ...

How to invoke a function from a different controller in Ionic 2

Is it possible to call a function in another controller within Ionic 2? Here is my code where I want to call the loadPeople function in the tab controller. home.ts import { Component } from '@angular/core'; import { NavController } from ' ...

Unusual behavior when importing in Angular 2 using TypeScript

While working on a demo for another question on Stack Overflow, I initially used angular-cli and then switched to Plunker. I noticed a peculiar difference in behavior with the import statement between the two setups. The issue arises with the second impo ...

What is the method for copying table data, including input text as cells, to the clipboard without using jQuery?

I have a basic table that looks like this: <table> <thead> <tr> <th>Savings</th> </tr> </thead> <tbody> <tr> <td>Savings <button type="button" (click)=" ...

"Looking for a way to create a new line in my particular situation. Any tips

Here is the code snippet I am working with: let list: Array<string> =[]; page.on('request', request => list.push('>>', request.method(), request.url()+'\\n')); page.on('respon ...

Issue: The key length and initialization vector length are incorrect when using the AES-256-CBC encryption algorithm

Within my coding project, I have developed two essential functions that utilize the AES-256-CBC encryption and decryption algorithm: import * as crypto from "crypto"; export const encrypt = (text: string, key: string, iv: string) => { con ...

Tips for denoting unnecessary non-null assertions in Typescript

Incorporated this wrapper (source) into the project I'm currently working on: export function expectToBeDefined<T>( arg: T, ): asserts arg is Exclude<T, undefined> { expect(arg).toBeDefined(); } The objective is to eliminate the usage ...

Webpack is struggling to locate core-js paths when running on Windows operating systems

When running webpack, I am encountering the following errors: ERROR in ./node_modules/core-js/index.js Module not found: Error: Can't resolve './es' in 'pathtoproject\node_modules\core-js' @ ./node_modules/core-js/index. ...

How can I make Vuejs update v-model when the text input is changed using Jquery?

I am currently working with 4 inputs that have a timeselector popup. The jquery timepicker plugin I am using does not seem to provide an obvious way to manipulate an input through a callback function. Interestingly, Vuejs does not detect changes made to th ...