虽然我添加了一个定义文件,但无法识别 Jasmin 方法(即 createSpyOjb)。
知道为什么会这样吗?
最佳答案
我的以下代码与 Definitely Typed 中的最新定义完美配合.
/// <reference path="node.d.ts" />
/// <reference path="jasmine.d.ts" />
var fs = jasmine.createSpyObj('fs', ['readfile']);
var callback = jasmine.createSpy('callback');
var rek = require('rekuire');
var proxykuire = rek('proxykuire').proxykuire;
var getMenuDataCommand = rek('GetMenuDataCommand');
describe('GetMenuDataCommand', function () {
var getMenuDataCommand;
var fs;
var callback;
beforeEach(function () {
fs = jasmine.createSpyObj('fs', ['readFile']);
callback = jasmine.createSpy('callback');
var getMenuDataCommand = proxykuire('GetMenuDataCommand', { fs: fs });
getMenuDataCommand = new getMenuDataCommand();
});
});
唯一的区别(除非我输入错误)是我的引用更接近我的 TypeScript 文件。我获得了完整的智能感知并且没有错误。
网络 Storm
我刚刚在WebStorm中测试过,它似乎不支持TypeScript 0.9,如果你使用WebStorm,这将是一个绊脚石。 (它无法识别 boolean
类型,也没有得到 export = internal;
支持)。
您可以使用较旧版本的定义(在它们更新到 TypeScript 0.9 之前)让您暂时使用,然后在 WebStorm 获得 0.9 语言支持时更新。
关于javascript - typescript : 'jasmine' 方法无法正确识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17948910/