xcatliu/typescript-tutorial

範例 compile 失敗

xuan0123 opened this issue · 0 comments

在範例 examples/declaration-files 的第三個範例 03-jquery-d-ts 中,在 tsconfig.json 內的 files option 無法讓 TypeScript compiler 知道全域的 jQuery 方法的宣告。

// tsconfig.json

{
  "files": ["src/index.ts", "src/jQuery.d.ts"]
}

錯誤訊息:

index.ts:1:1 - error TS2304: Cannot find name 'jQuery'.

1 jQuery('#foo');
  ~~~~~~


Found 1 error.

一定要在 index.ts 中給三斜線 reference path。

// src/index.ts

/// <reference path="./jQuery.d.ts" />

jQuery('#foo');