【问题标题】:How to stop warnings for functions without DefinitelyTyped?如何停止没有绝对类型的功能警告?
【发布时间】:2016-06-28 03:34:33
【问题描述】:

如果某些函数或库没有DefinitelyTyped,我知道这两种停止警告的方法。

interface Navigator {
  getUserMedia: any
}

declare let RTCIceCandidate: any;

但是现在,这个第 3 部分库 Collection2 是这样使用的:

let ProductSchema = {};
let Products = new Mongo.Collection('products');
Products.attachSchema(ProductSchema);

它给了我一个警告:

类型“Collection”上不存在属性“attachSchema”。

我尝试了下面的方法,但它不起作用。

interface Collection {
  attachSchema: any
}

如何停止此警告?谢谢

编辑:

Eric 添加any 的方式解决了这个问题。

let Products:any = new Mongo.Collection('products');
Products.attachSchema(ProductSchema);

但现在新的麻烦来了:

let UserSchema = {};
Meteor.users.attachSchema(UserSchema);

由于Meteor.users是内置的,所以没有地方添加any。如何解决这个问题?谢谢

【问题讨论】:

  • 错误是完全正确的。 These 是 javascript 中字符串可用的所有方法。
  • @EricMartinez 谢谢,我实际上想以字符串为例,所以现在我更具体地更改了我的问题
  • 你试过let Products: any = new Mongo.Collection('products');吗? (注意any
  • @EricMartinez 哇,这是个好技巧,哈!谢谢!
  • 像这样:(Meteor.users).attachSchema(UserSchema);

标签: meteor typescript angular meteor-collection2 angular2-meteor


【解决方案1】:

感谢阿米德的帮助。所以方法是:

(<any>Meteor.users).attachSchema(UserSchema);

【讨论】:

    猜你喜欢
    • 2022-06-15
    • 2021-01-05
    • 2013-10-13
    • 1970-01-01
    • 1970-01-01
    • 2012-02-23
    • 2012-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多