【问题标题】:TypeScript, Backbone and RequireJS - public / private issue when creating collectionTypeScript、Backbone 和 RequireJS - 创建集合时的公共/私人问题
【发布时间】:2012-12-02 11:50:01
【问题描述】:

我正在尝试开始使用 TypeScript 和 Backbone,我的所有类都在单独的文件中,使用 RequireJS。我有一个模型和一个集合:

EntityModel.ts:

/// <reference path="../modules/backbone.d.ts"/>
export class EntityModel extends Backbone.Model{
}

EntityCollection.ts

/// <reference path="../modules/backbone.d.ts"/>
import em = module("../models/EntityModel");
export class EntityCollection extends Backbone.Collection{
   model = em.EntityModel;
}

我收到一条错误消息:

导出类的公共成员“模型”已经或正在使用私有类型“em”

我只是想告诉它我的收藏要使用什么类型的模型,但似乎在第一个障碍中落下!

【问题讨论】:

    标签: backbone.js requirejs typescript


    【解决方案1】:

    找到答案:http://typescript.codeplex.com/discussions/405800

    导出您的进口!

    export import em = module("../models/EntityModel");
    export class EntityCollection extends Backbone.Collection{
       model = em.EntityModel;
    }
    

    【讨论】:

    • 郑重声明,export import 解决方法只是暂时的,直到错误被修复。 export import 也有可能在以后的版本中失效 - 所以这个变通办法可能只在 TypeScript 的 0.8.1.1 版本中有效。
    • 感谢史蒂夫 - 非常感谢!
    猜你喜欢
    • 2014-08-21
    • 2016-11-24
    • 1970-01-01
    • 2014-11-07
    • 2015-12-11
    • 1970-01-01
    • 2016-05-30
    • 2012-05-14
    • 1970-01-01
    相关资源
    最近更新 更多