A guide to activating TypeScript-exclusive Props Typing in Vue3

In accordance with the old function RFC, Vue3 is set to support TypeScript-only props typing. However, when I tested the following code, it appears not to be working as expected and Props are returning as undefined.

interface MessageProps {
  msg: string;
  list: any[];
}
export default defineComponent({
  name: 'HelloWorld',
  setup(props: MessageProps) {
    console.log(props)
  }
})

Answer №1

Currently, the declaration of props is still necessary, despite the RFC suggesting it's optional. There seems to be no discussion on this specific feature, so I assume it hasn't been implemented yet.

In the interim, specifying the props as demonstrated below should resolve any issues:

export default defineComponent({
  // declaration required as of [email protected]
  props: {
    msg: String,
    list: Array,
  },
  setup(props: MessageProps) { /*...*/ }
})

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

Make changes to the database according to the selected div

Within this small box section, recent uploads are displayed along with a status indicator - red for pending and green for uploaded. Currently, clicking on the first red box will update all red ticks to green, marking them as completed. Is there a way to m ...

Using React TypeScript to trigger a function upon route changes with react-router-dom

I am trying to use the useEffect hook to console log every time the location changes in my project. However, when I try to compile, I receive an error in the terminal saying Unexpected use of 'location' no-restricted-globals. I would like to fin ...

Using the mt-downloader module in a Node application is a straightforward process

Hey there, I'm looking to incorporate the Multi downloader module into my project. I've checked out the GitHub link, but unfortunately, there are no examples provided on how to actually use this module. I came across this example and tried implem ...

Utilize vibrant spectrum hues for the SVG design in Fabricjs

Applying spectrum color to all objects in SVG by storing unique colors in an array and displaying them in a spectrum. The goal is to change object color using the spectrum color picker. SVG used in this program: Tiger SVG View Working Demo here: JS Fidd ...

Exploring Angular: Embracing the Power of Query String Parameters

I've been struggling with subscribing to query string parameters in Angular 2+. Despite looking at various examples, I can't seem to make it work. For instance, on this Stack Overflow thread, the question is about obtaining query parameters from ...

Animating a div to move up and down upon clicking using jQuery

Looking for a solution with my HTML setup: <div id="one">One</div> <div id="two">Two <br/> <br/> Two </div> <div id="three">Three</div> <div id="four">Four <br/> <br/> Four < ...

Postman is having trouble communicating with an express router and is unable to send requests

Currently, I am experiencing some challenges while trying to grasp the concepts of express and node with typescript, particularly when setting up a router. In my bookRoutes.ts file, I have defined my router in the following manner: import express, { Expre ...

Adding a see-through Bootstrap Navbar to a Fullpage.js website: A step-by-step guide

I am trying to incorporate a transparent Bootstrap Navbar into my page that is using fullpage.js. The desired outcome is for the navbar to stay on top of the page without affecting the layout of the website content. I have referenced an example here, but ...

Divide the string into an array by splitting it on white space located before the 10th

I am looking for a way to break a string into chunks of 10 characters without splitting words. For example, the string "Nine characters to go - then some more" should be split into ["Nine", "characters", "to go -", "then some", "more"]. Words longer tha ...

The width and height properties in the element's style are not functioning as expected

let divElement = document.createElement("div"); divElement.style.width = 400; divElement.style.height = 400; divElement.style.backgroundColor = "red"; // num : 1 divElement.innerText = "Hello World "; // num : 2 document.body.append(divElement); // Af ...

Exploring TypeScript's reluctance to automatically infer value types and strategies for overcoming this behavior

I have been working on implementing a type-safe router in TypeScript and I am facing challenges with inferring types. export interface Route<Args> { match(path: string): Args | void; build(args: Args): string; } export type Routes<State> ...

Having trouble sending an HTTP request to my .Net Core 2.1 web project

In my current project, I am working with Angular 6 and .Net Core 2.1. The Angular 6 code is in one project, while the .Net Core 2.1 controller methods for login authentication are in another project. I have noticed that both projects are using different lo ...

Utilizing document.write to switch up the content on the page

Every time I attempt to utilize document.write, it ends up replacing the current HTML page content. For instance, consider this HTML code: <body> <div> <h1>Hello</h1> </div> and this jQuery code: var notif = document. ...

modifying the color of a header in a v-list

I am trying to customize the color of a v-list header item. It seems that I can only change the color of the title, not the entire tile. I need this to be reactive because the background color I want to change will vary over time. I attempted using the co ...

Utilizing Dexie-Query for Real-Time Data Updates in Vue

I am currently utilizing Dexie within my Vue 3 frontend and aiming to seamlessly integrate it. Within the mount() method, I execute a database query similar to the example below, storing the result in a local variable within the Vue template for rendering ...

Guide to making a dynamic hyperlink in VueJS using filtered or modified data

I am developing a VueJS application that receives data in the following format: data: function() { return { posts: ['1:foo bar oof rab', '2:bar oof rab foo', '3:oof rab foo bar'] } } My goal is to create a template t ...

Exploring the Power of Arrays, For-Loops, and Functions in JavaScript

Currently, I have a functional code implementation, but I'm struggling with creating a proper loop. I'm seeking a solution to develop a function that changes the URL source of #mainImage to the one in the imgUrl array when hovering over an #id i ...

Turn off the Right click option on an .aspx page, but allow it on a Hyper

Can the right click be disabled on a webpage while still allowing it on hyperlinks within the same page? I am aware that I can disable right click, but if there is a way to allow it on hyperlinks, please provide the code. The main reason for disabling rig ...

Using Lodash to eliminate objects from a list

I have a specific model for my list, it looks like this: Animal Model id name age gender city Within the animals[] = []; array that I am working with, I need to remove the fields name, age, and gender while keeping id and city. How c ...

What factors contribute to the variations in results reported by Eslint on different machines?

We initially utilized tslint in our project but recently made the switch to eslint. When I execute the command "eslint \"packages/**/*.{ts,tsx}\"" on my personal Windows machine, it detects 1 error and 409 warnings. Surprising ...