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

Angular 2: Issue with disabled functionality not functioning correctly

In my TypeScript code, I have created a boolean variable called readOnlyMode. When this variable is set to true, all elements should be disabled. To achieve this, I am using [disabled]="readOnlyMode" in the HTML for elements that need to be disabled. Howev ...

Merging Vue.js with vue.router in history mode and Django unfortunately results in an error

When I set publicPath to '/static/' in my webpack configuration, everything works smoothly with my Vue.js app on a Django Webserver for both development and production environments. However, when attempting to implement history mode, I need to m ...

Contrasting the functions of this.$parent.$emit and this.$emit

When looking to have a custom component trigger an event in VueTable2, it is important to remember that we should use: this.$parent.$emit('myCustomEvent') // as opposed to this.$emit('myCustomEvent') The insights shared in this discu ...

The issue of resolving NestJs ParseEnumPipe

I'm currently using the NestJs framework (which I absolutely adore) and I need to validate incoming data against an Enum in Typscript. Here's what I have: enum ProductAction { PURCHASE = 'PURCHASE', } @Patch('products/:uuid&apos ...

Invoke a function in a different component by utilizing the composition API

Provided below is a code snippet for a header and a body in different components. How can you leverage the composition API to call the continue function of component 2 and pass a parameter when you are within component 1... Code Snippet for Component 2: e ...

Attempting to showcase data retrieved from various API calls

I am currently facing an issue where I am retrieving stock/share names from my MongoDB database and attempting to display their prices by making API calls for each of them in my component. However, I am only receiving the price for the last stock. Below i ...

Bring in functions from another Vue page using the import methods

Recently, I've started working with Vue and I have a project where I'm dealing with two components: A.vue and B.vue. In A.vue, there are some functions defined in the methods section that I'd like to use in B.vue. Since these components ar ...

Issue with navigating history back in Angular 7 using an iframe

I'm currently working on a single-page application using Angular. I encountered an issue where, when the user presses the browser's back button, only the YouTube iframe content updates and not the entire page. This results in having to press the ...

Moving SVG Module

My goal is to create a custom component that can dynamically load and display the content of an SVG file in its template. So far, I have attempted the following approach: icon.component.ts ... @Component({ selector: 'app-icon', templa ...

Allow Visual Studio Code to create a constructor for Typescript class

When developing Angular 2 apps in Typescript using Visual Studio Code, one common task is writing constructors with their parameter list. Is there a way to save time and effort on this? It would be really helpful if the IDE could automatically generate th ...

next.js users may encounter a problem with react-table not rendering correctly

Encountering difficulties while attempting to integrate a basic table function into my upcoming application. Despite being a sample output, the function fails to load into the index for some unknown reason! // Layouts import Layout from "../components ...

`Is there a way to effectively test an @Input component in Angular?`

Despite multiple successful attempts in the past, I am facing some difficulty getting this to function properly. Within my component, I have an input @Input data: Data, which is used in my template to conditionally display certain content. Oddly enough, du ...

Utilize Angular's $state service within a configuration setting to automatically redirect to a specific state using an interceptor

I'm working with restangular and have set up an interceptor to handle 401 responses by redirecting to another state. The issue is that angular only allows the injection of providers, not services, in config. Is there a way to access the $state: ng.u ...

Compiling async code with generators in Typescript proves to be challenging

Scenario As I delve deeper into Typescript, I've come across the advice that blocking calls should not be made within asynchronous code. I have also found generators to be helpful in simplifying directory traversal and preventing stack overflow. ...

Looking for help with setting up Nodemailer and installing it via NPM

I am currently developing a mobile application using Ionic with Angular/Typescript, and I'm in need of a front-end solution to dynamically send emails in the background to a specific email address. I tried using emailjs, but it requires JavaScript whi ...

The ng2-chart library displays date in the form of a Unix timestamp

I have a date object imported from my database, but it is showing up as a Unix timestamp (-62101391858000). I know I can format the date using pipes like {{myDate | date:medium}}, however, I am using ng2-charts so I need to find a different solution. My ch ...

Uh oh, it looks like there's an issue! The function getCoordinates is not recognized for this.locations

Whenever I attempt to execute the method in my class (getCoordinates()), an Error is thrown: ERROR TypeError: this.locations[0].getCoordinates is not a function What am I doing wrong? The service method I'm using: getLocations(){ return this ...

The npm script for running Protractor is encountering an error

Currently, I am facing an issue while trying to execute the conf.js file using an npm script. The conf.js file is generated within the JSFilesRepo/config folder after running the tsc command as I am utilizing TypeScript in conjunction with protractor-jasmi ...

Vue.js is displaying one less item

Recently I started working with Vuejs and encountered an unexpected issue in my application. The purpose of my app is to search for channels using the YouTube API and then display those channels in a list. However, when I try to render the list of subscri ...

The variable 'firebase' is nowhere to be found

I am encountering an issue with the error message 'Can't find variable: firebase' and I am struggling to identify the cause of this error. I have installed firebase using 'yarn add firebase' and double-checked that it is properly i ...