错误消息
Compile Error. See error list for details .../Scripts/gallery.ts(13,15): The name 'Size' does not exist in the current scope
画廊.ts
/// <reference path="jquery.d.ts" />
/// <reference path="jquery.custom.js" />
(function ($) {
var $body = $(document.body);
var $win = $(window);
var animTime = 1000;
var $cg = $('#control_grid').data('flash', false);
function fitImage(img, max, enlarge) {
var ratio = Math.max(img.width / max.width, img.height / max.height);
if (ratio < 1 && !enlarge) ratio = 1;
return Size(Math.round(img.width / ratio), Math.round(img.height / ratio));
}
...
jquery.custom.js
function Size(w, h) {
return {
'width': w,
'height': h
};
}
...
问题
当我将鼠标悬停在 Visual Studio 中的 gallery.ts
中的“Size”上时,它会显示正确的定义,因此它可以清楚地找到该函数。为什么 TS 编译器会给我这个错误?
Size()
函数位于 jquery.custom.js
的根级别,它应该具有全局作用域,不是吗?
最佳答案
您不会通过引用 JavaScript 文件来获取类型信息。您可以在 TypeScript 中编写该函数,也可以为其创建一个定义文件,即 jquery.custom.d.ts
。
关于typescript - "name ' 大小 ' does not exist in the current scope"即使我 've referenced it and it isn' t 突出显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14045759/