【发布时间】:2014-05-06 22:43:07
【问题描述】:
我正在使用带有 durandal 的打字稿作为概念证明,老实说,它们并没有凝胶化。
最近我正在尝试解决以下智能感知错误:
“无法将 calendarServiceImport 类型转换为 ICalendarService”
///<reference path="service/CalendarService.ts"/>
import calendarServiceImport = require("service/CalendarService");
var calendarService: ICalendarService;
calendarService = calendarServiceImport;
对于 Durandal,导入调用应该是一个 DI 调用并且应该是一个实例,但是 typescript 解析器认为它应该是一个类型。
这是我要导入的代码:
/// <reference path="../contracts/ICalendarService.ts"/>
/// <reference path="../../configure.d.ts"/>
import configuration = require('viewmodels/configure')
class CalendarService implements ICalendarService {
private NumberOfDaysToSync : number;
constructor() {
}
getCalendarNames(): string[] {
return ["My Calendar","My Other Calendar"];
}
pullLatestSchedule(calendarName : string) {
}
}
export = CalendarService;
我可以摆脱错误,但我会引入逻辑错误,这更糟糕,因为这将是一个应用程序错误。
例如。替换以下行:calendarService = calendarServiceImport; 与 calendarService = new calendarServiceImport(); 但没有意义,因为我将第二次实例化该对象。
如何解决这个错误?
【问题讨论】:
标签: javascript requirejs typescript durandal durandal-2.0