The error message "Cannot find property 'email' in type '{setup():{email : Ref<string>; password: Ref<string> }}'" is being displayed

Currently experimenting with vue js 3 and typescript in the composition API while utilizing firebase for authentication

<template>
      <input placeholder="Password" @input="this.password"/>
</template>
<script lang="ts">
import { ref } from "vue";
import { useRouter } from "vue-router";
import { getAuth, createUserWithEmailAndPassword } from "firebase/auth";
export default {
setup() {
const router = useRouter();
const email = ref("");
const password = ref("");
const gender = ref("Male");
const registerUser = () => {
  createUserWithEmailAndPassword(getAuth(), this.email, this.password)
    .then((data) => { 
      router.push("/");
    })
    .catch((error) => {
      console.log(error);
    });
}
return {
  email,
  password,
  gender,
  registerUser,
};

},

Encountering errors related to both email and password :

Property 'email' does not exist on type '{ setup(): { email: Ref; password: Ref; gender: Ref; registerUser: () => void; }; methods: {}; }'.

Error displayed in the browser during feature testing:

TypeError: Cannot read properties of undefined (reading 'email')

Answer №1

There are a few key points to address here. Firstly, it's worth noting the use of passing a reference as your @input callback and utilizing this.password in Vue.js template tags. Generally, it's recommended to omit the use of this before setup variables in template tags. Perhaps what you intended to do was:

<input placeholder="Password" v-model="password"/>

Secondly, there is no need to prefix email and password with this in the arguments for createUserWithEmailAndPassword.

Lastly, since your email and password are treated as "Refs", they are essentially objects with proxies in your script. To access them correctly, consider updating your syntax as follows:

createUserWithEmailAndPassword(getAuth(), email.value , password.value)

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

Using .appendChild in Vue.js to dynamically add elements and then attaching v-model to them is a powerful combination

I am currently facing a challenge where I need to work with a library that does not have a Vue.js wrapper. This particular library dynamically appends elements in the DOM. My goal is to bind the v-model attribute to these dynamically appended elements usi ...

When the Firebase "value" event is triggered, both the "then" and "catch" functions will be called simultaneously

Seeking clarity, I am utilizing two interconnected functions and incorporating error-handling techniques. The then and catch for function A() are functioning correctly. However, the issue arises with function B() where both then and catch are being trigger ...

Issue with Firebase Admin Module: Unable to locate '@firebase/app' in NextJs

I am currently working on a project that utilizes Vercel's NextJS build in combination with Firebase Hosting. I have successfully integrated Firebase functions into my project, and in the firebaseFunctions.js file, I set up an export to share the Fire ...

Utilize multiple validators.patterns within a single value for enhanced data validation

I need to implement two different patterns for the formControlName='value' based on the type selected. If type is 'A', I want to use the valuePattern, and if type is 'B', I want to use the uname pattern. This is my HTML code: ...

What is the most efficient method for restoring an object's color to its original state?

Currently, I am working on a typescript program that involves manipulating a collection of objects, all initially colored red (e.g. cup.material.color is red). My goal is to be able to change the color of one object, such as a cube, by pressing a certain ...

Ways to Update/Overwrite Current Information in HTML Using Vue

I have experience creating templates for Vue components using JavaScript. Imagine I have HTML that is generated on the server side with a language called UTL: <table> <tr> <td>[% example_var; %]</td> <t ...

My customized mat-error seems to be malfunctioning. Does anyone have any insight as to why?

Encountering an issue where the mat-error is not functioning as intended. A custom component was created to manage errors, but it is not behaving correctly upon rendering. Here is the relevant page code: <mat-form-field appearance="outline"> < ...

An Unexpected Typescript Error Occurred While Creating an RxCollection With RxDB

I'm new to RxDB and I've come across a strange Typescript error in my Electron project. Here are the relevant parts of my code: import RxDB, { RxCollection, RxDatabase } from "rxdb"; RxDB.plugin(require("pouchdb-adapter-idb") ...

Encountering 'canvas.node' Issue While Setting up react-pdf-viewer with Next.js and TypeScript

I am having trouble integrating the "react-pdf-viewer" package into my Next.js project using TypeScript. I have downloaded the package via npm and followed the instructions in the documentation. However, when I try to compile my project, I encounter the fo ...

The process on how to access dynamic object properties within a parent component while using v-for in a child component

I am working on a child component that utilizes v-for to loop through data. Below is the code for the child component: <template> <div> <ul> <li v-for="item in listItems" :key=item.id&g ...

The process of adding new files to an event's index

I'm trying to attach a file to an event like this: event.target.files[0]=newFile; The error I'm getting is "Failed to set an indexed property on 'FileList': Index property setter is not supported." Is there an alternative solution fo ...

How is it possible for the igx-expansion-panel to close when there is a nested angular accordion present?

Currently, I am faced with the challenge of closing the igx-expansion-panel within my Angular project. While everything functions smoothly with a standard panel, things get a bit tricky when dealing with nested angular accordion structures using igx-accord ...

Creating a Vue 3 Typescript project may lead to encountering the error message "this is undefined"

Just diving into Vue using Vite and TypeScript for my project, but running into errors during the build process. Most of them are Object is possibly 'undefined', particularly in parts of my template like this: <input :value="this.$store.s ...

How can you share a variable with all Vue components without the need to pass it through props every time?

One thing I'm curious about is the use of react consumer and provider for passing variables in React. Does Vue offer a similar feature? I have a Firebase class that needs to be passed to almost every component, and passing it through props doesn&apos ...

Why does the property of {{hero.name}} function properly in a <h> tag but not in an <img> tag?

Within this template, the code below functions correctly: <h3>{{hero.name}}</h3> It also works for: <a routerLink="/details/{{hero.id}}">{{hero.name}}</a> However, there seems to be an issue with the following image path ...

Leveraging Interface in Protractor Testing

As a newcomer to Typescript and Protractor, I have been working with reusable code in various classes. Instead of importing each library class separately into my test class, I am trying to find a way to import just one class or interface that will contai ...

Using Vue with Typescript to leverage generics for interfaces

What is the proper syntax for allowing any type that extends a base type in this specific scenario? interface SomeBase {} interface A extends SomeBase {} interface B extends SomeBase {} interface Foo { bar: // Can be an array of A or B } Is it simply ba ...

What is the best way to transform a string into emojis using TypeScript or JavaScript?

Looking to convert emoji from string in typescript to display emoji in html. Here is a snippet of the Typescript file: export class Example { emoji:any; function(){ this.emoji = ":joy:" } } In an HTML file, I would like it to dis ...

Tips for handling delayed HTTP API responses in Angular

While working on my project, I encountered a delay in response when using the this.ServiceHandler.getTxnInfo([], params) API. To handle this, I implemented the use of setTimeout along with async/await. Despite these modifications, my promise ended up being ...

Unable to vertically scroll on a position fixed element

I recently created a unique VueJS component that enables vertical scrolling. Within this component, there are two elements each with a height of 100vh. At the bottom of the component is a fixed position div. Interestingly, when I try to scroll down using m ...