.d.ts文件中的“预期类型”

时间:2016-01-15 00:16:27

标签: typescript

有人可以解释为什么会失败,以及如何纠正它?

https://travis-ci.org/DefinitelyTyped/DefinitelyTyped/builds/102481354

class Article
  include Mongoid::Document
  field :title, type: String
  field :body, type: String
  has_and_belongs_to_many :categories

  def category_articles
    output = []
    categories.each do |cat|
      output << cat.articles.pluck(:title)
    end
    return output.flatten.join(', ')
  end

  rails_admin do
    list do
      include_all_fields
      field :category_articles
    end
  end
end

似乎函数参数可以接受文字值,但不能作为函数参数中对象字段的限制。最好的方法是什么?

https://github.com/nalbion/DefinitelyTyped/blob/master/google.analytics/ga.d.ts

google.analytics/ga.d.ts(59,22): error TS1110: Type expected.
google.analytics/ga.d.ts(64,37): error TS1005: ',' expected.
google.analytics/ga.d.ts(64,38): error TS1128: Declaration or statement expected.
google.analytics/ga.d.ts(64,39): error TS1128: Declaration or statement expected.

1 个答案:

答案 0 :(得分:2)

  

hitType:&#39; event&#39;,

这需要对字符串联合的支持虽然已添加到TypeScript最新版本尚未作为稳定版本发布,因此绝对类型的架构不支持它。