【问题标题】:Meteor & TypeScript - Error: The property 'confirm' does not exist on value of type '{}'Meteor & TypeScript - 错误:“{}”类型的值不存在“确认”属性
【发布时间】:2015-02-16 22:12:12
【问题描述】:

我正在使用 Meteor 和 TypeScript 开发一个 Web 应用程序,也使用 Nitrous.io 环境。

我正在尝试实施用户帐户系统。我正在修改旧项目中的 JavaScript 代码(它有效),但我仍然遇到错误。这是来自 login.ts 文件:

// 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
        } 

我收到的错误消息是:

/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 '{}'.

有什么想法吗?谢谢。 :)

【问题讨论】:

    标签: meteor typescript nitrousio meteor-accounts typescript1.4


    【解决方案1】:

    将错误对象更改为此。

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

    你也可以抛出错误对象(每个浏览器都支持这两个属性)

    1. name - 错误的名称
    2. 消息 - 错误描述

    或自定义错误。

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

    如果您对抛出错误感兴趣,请查看this article

    【讨论】:

      猜你喜欢
      • 2013-08-07
      • 2023-02-21
      • 2019-04-12
      • 2020-07-09
      • 2019-10-20
      • 2021-09-26
      • 1970-01-01
      • 2021-09-06
      • 2016-09-07
      相关资源
      最近更新 更多