meteortypescriptnitrousiometeor-accountstypescript1.4

Meteor & TypeScript - Error: The property 'confirm' does not exist on value of type '{}'


I'm developing a web application with Meteor and TypeScript, also using the Nitrous.io environment.

I'm trying to implement a user account system. I'm adapting JavaScript code which I had in my old project (it worked), but I'm still getting errors. This is from the login.ts file:

// retrieve the input field values
        var email = template.$('[name=email]').val();
        var password = template.$('[name=password]').val();

        var errors = {};

        if (! email) {
            errors.email = 'Please enter your email address';     // ERROR HERE
        }

        if (! password) {
            errors.password = 'Please enter your password';       // ERROR HERE
        } 

The error messages I'm getting are:

/client/login.ts(41,20): error TS2094: The property 'email' does not exist on value of type '{}'.                                                                                                                                           

/client/login.ts(45,20): error TS2094: The property 'password' does not exist on value of type '{}'.

Any ideas? Thanks. :)


Solution

  • Change the errors object to this.

    var errors = {
       email:"",
       password:""
    };
    

    You can also throw the error object (wich on every browser support this 2 properties)

    1. name - The name of the error
    2. message - A description of the error

    or a custom error.

    if (! email) {
                throw new Error('Please enter your email address')     // ERROR HERE
            }
    
            if (! password) {
                throw new Error('Please enter your password')       // ERROR HERE
            } 
    

    Check this article if you interested on throwing errors