What is the reason for TS expressing dissatisfaction about the use of a type instead of a type entry being provided

Below is a snippet of code for a Vue3 component that takes in an Array of Objects as a prop:

<script lang="ts">

interface CorveesI {
  What: string,
  Who: string,
  Debit: number
}

export default {
  name: 'Corvees',
  props: {
    corvees: {
      type: CorveesI[]
    }
  },
(...)

During compilation, there is a warning specifically on the line type: CorveesI[]:

TS2693: 'CorveesI' only refers to a type, but is being used as a value here.

Uncertain about how to address this issue, as I am specifying the type of corvees, providing a type but then told it's expected as a value.

I consulted the documentation on Type Checks but couldn't connect the dots between my interface and the constructor.

Fearing my understanding of interface may be flawed, I delved into the TS doc for Object Types but found it more like a type description (similar to type in Golang, for example). Consequently, confusion heightened.

Answer №1

When defining props in Vue components, it's important to remember that the expected types are JavaScript runtime types, not TypeScript types. This means that only the types mentioned in the Vue documentation are valid for props.

If you want to properly type a prop in TypeScript, you should use PropType<>. You can learn more about this by reading the documentation on Annotating props

import { PropType } from "vue";
...
corvees: {
  type: Array as PropType<CorveesI[]>
}

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

Why does the Vue i18n $t('hello') not function properly within a data property until the page is refreshed, yet it works fine when used in a normal template?

**Below are the components I require assistance with: The home component contains an array that needs to have its title and content translated, then binded as props to the info component. Since $t does not work with data method, how can I accomplish this u ...

typescript React-Redux challenge: Boosting Your mapDispatchToProps Skills

I'm having trouble determining the type of my mapDispatchToProps function in the SignInComponent. See the code snippet below: Here is my authAction.ts file: import firebase from 'firebase/app' import { Dispatch } from 'react'; ty ...

Challenges with Vuetify forms

I have created a popup form with modularity using Vuetify. However, I encountered an issue where clicking on the email input field, deselecting it to trigger an "empty" error, and then switching over to the register tab caused a similar error for the name ...

What causes the error "Angular 2 checkbox params.setValue is not functioning properly"?

import { Component } from '@angular/core'; import { GridOptions, RowNode } from 'ag-grid/main'; import { ICellRendererAngularComp } from 'ag-grid-angular'; @Component({ selector: 'qrp-drop-down-selector', ...

Using *ngFor to populate an array in an ion-list within Ionic 2

Hi there, I'm currently learning Ionic 2 and I recently created an array that I want to loop through in an ion-list. This is my produk.ts import { Component } from '@angular/core'; import { NavController, NavParams } from 'ionic-angul ...

Why is it that TypeScript's flow analysis does not extend to the 'else' block?

Consider the code below: function f(x : number) { if (x === 1) { if (x === 2) {} // error } else { if (x === 1) {} // OK } } The compiler flags an error on x === 2. This is because if the code reaches this block, x must be ...

Tips on storing and retrieving data between pages in Ionic 4/5: Saving data to a service and accessing it from a

Looking for assistance from the community I am trying to pass data between pages using a service in Angular. Here is the code for the parent component.ts file: import { Component } from '@angular/core'; import { ShareService } from '../sh ...

Is there a method to retrieve Mui state classes easily?

One thing I really appreciate is the way to style mui-components with their class names. I'm curious if there's a method to access state classes like Mui-checked using a variable. Let me delve deeper into this: I have a styled component that lo ...

Guide on adding checkboxes for each child component in a Vue ads table

<vue-ads-table :columns="fields" :rows="items" :selectable="true" @row-selected="onRowSelected" class="my-table" ...

Get React-table TS up and running on your local machine using VS Code

Objective: I am trying to get React-table working with TypeScript on my local computer. Challenge: The code is based on this page https://codesandbox.io/s/gkzg3?file=/src/makeData.ts However, when I attempt to apply the code on my local computer, I ...

What could be the reason for the undefined initial state in my vuex store?

I am facing an issue with vuex-typescript where the initial state is always undefined. However, it works fine when I reset the state and refresh the window. Below is my setup for a simple module: import Vue from "vue"; import Vuex from "vuex"; import { m ...

Tips on modifying the selected type key name through Pick?

I currently have this structure: type Product = { name: string } and I am looking to extract the name property and use it in a different type declaration like so: type NewProduct = Pick<Product, 'name'> Now, I want to rename name as new ...

Utilizing Axios for transmitting an authentication token to the server

I'm just starting out with this project Currently, I am developing a Vue application that connects to a WordPress backend and requires user login. To achieve this, I have implemented the Simple JWT-Login plugin. I've successfully managed to send ...

What is GraphQl indicating when it informs me that I neglected to send arguments for the mutation

My GraphQL schema consists of various mutations and queries. I believe that validation of mutations should only occur when I send mutation { ... } to the graphql server. However, currently, the server is informing me that I have not sent arguments for all ...

Vue.js - Trouble with Rendering Elements

I'm facing an issue with displaying data fetched from an API using axios in Vue.js. Despite writing the code, the elements are not being rendered and don't appear in the elements console. See below for the code snippets: <div class=" ...

Exploring Aurelia's Integration with ASP.NET Core Models

Recently, I've been delving into various JavaScript frameworks and made the decision to rework an ASP.Net Core MVC frontend using Aurelia. To kick things off, I utilized the SPA template. Everything has been smooth sailing so far - I’ve integrated ...

The challenge of extending a TypeScript generic to accept an Array type with unrelated elements

I have a function that resembles the following mock: // All properties in this type are optional. interface MyType { a?: string } // The return result type of `cb` is kept as the final result type. const f = <T extends ReadonlyArray<MyType>> ...

initialize input data in vue

How can I set a default value for an input in a date picker using Vue JS? I have tried setting the data but it's not showing up. When I inspect the element, I see this code: https://i.stack.imgur.com/fQDLL.png Here is my script: new Vue({ e ...

Manipulating nested lists in Vuejs by removing elements

After reading about how to remove elements from lists in VUEJS on Stack Overflow, I came across various methods like this.$remove, splice, and this.$delete. I was curious about applying these methods to a nested loop structure in my code which goes three l ...

The powerful combination of harp.gl and Angular NG

We've integrated harp.gl into our ng Angular application, but we're encountering issues when trying to connect to data sources that previously worked in our yarn demo. The datasource is created as follows: const dataSource = new OmvDataSour ...