1amageek / pring.ts

Cloud Firestore model framework for TypeScript - Google
https://firebase.google.com/docs/firestore/
MIT License
108 stars 7 forks source link

Class constructor Base cannot be invoked without 'new' #45

Open gduggirala opened 5 years ago

gduggirala commented 5 years ago

Created a new model called Recipient

import {RegistrationStatus} from "./RegistrationStatus"
import * as Pring from "pring"

const property = Pring.property;
const File = Pring.File;

export class Recipient extends Pring.Base{

    @property _id?: string
    @property fullName: string = ""
    @property email: string = ""
    @property country: string = ""
    @property gender: string = ""
    @property dateOfBirth: Date = new Date()
    @property _status: RegistrationStatus = RegistrationStatus.NotRegistered

    set gaurdianName(gaurdianName: string){
        this.gaurdianName = gaurdianName
    }

    set gaurdianPhone(gaurdianPhone: string){
        this.gaurdianPhone = gaurdianPhone
    }

    set state(state:string){
        this.state = state
    }

    set recipientNumber(recipientNumber:string){
        this.recipientNumber = recipientNumber
    }

    set addressLine1(addLine1:string){
        this.addressLine1 = addLine1
    }

    set addressLine2(addLine2:string){
        this.addressLine2 = addLine2
    }

    set city(city:string){
        this.city = city
    }

    set search(search:Array<string>){
        this.search = search
    }

}

And iam trying to use this in the component as follows.

@Component
export default class HelloWorld extends Vue {
  @Prop() private msg!: string;
  @Emit()
  async onClick(): Promise<void>{
    console.log("I am inside click event...")
    let recp = new Recipient();
    recp.fullName = "My full name"
    recp.recipientNumber = "+1 888 999 0000"
    recp.email = "myemail@emaildomain.com"
    recp.city = "City name"
    let temp = await recp.save().catch(e=>{
      console.log("Error while saving ", e)
    })
    console.log("Temp received after storing is ", temp)
  }
}

I used https://github.com/1amageek/vue-pring-sample project and just added above code. After adding the above code I am getting the following error.

Uncaught (in promise) TypeError: Class constructor Base cannot be invoked without 'new'
    at new Recipient (Recipient.ts?8a02:18)
    at _callee$ (VM3962 HelloWorld.vue:45)
    at tryCatch (runtime.js?96cf:62)
    at Generator.invoke [as _invoke] (runtime.js?96cf:288)
    at Generator.prototype.(:8080/anonymous function) [as next] (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:114:21)
    at eval (tslib.es6.js?9ab4:71)
    at new Promise (<anonymous>)
    at Module.__awaiter (tslib.es6.js?9ab4:67)
    at VueComponent.onClick (VM3962 HelloWorld.vue:36)
    at VueComponent.emitter (vue-property-decorator.js?60a3:112)

I am new to typescript and dont know how to interpret the errors, any help is appreciated.

Thank you,

praveenrejeti commented 5 years ago

Initially me also faced the same issue but after research and debug came to know that we have to configure tsconfig properly :100:

It's working by adding the repo dependency instead of installing from npm.