How to get rid of <reference path="

霸气de小男生 提交于 2019-12-12 20:25:39

问题


Sorry everyone, I've been struggling trying to understand why I need the

/// <reference path="../typings/browser.d.ts" />

module App {
    angular.module("app", [""]);
}

I'm using typings and here is my tsconfig:

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "module": "commonjs"
  },
  "files": [

  ],
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

I found already several posts about, but every time a different answer and a different scenario.

I use Visual Studio 2015 with ReSharper, TypeScript 1.8.5

Once I remove <reference... tag ReSharper says "Cannot find name 'angular'" but the application runs normally. (probably because it cannot find the intellisense anymore)

Has anyone faced the same problem? Am I missing something?


回答1:


From the docs on tsconfig:

If no "files" property is present in a tsconfig.json, the compiler defaults to including all TypeScript (*.ts or *.tsx) files in the containing directory and subdirectories. When a "files" property is present, only the specified files are included.

You are using an empty files array ("files": []) which means no files are going to be included in the compiler context. Either add all your references to the files array, or remove the files property completely to allow the compiler to include all TS files in context.

Alternatively, you can use import and export module syntax instead.




回答2:


I use one _reference.ts file with all referenced *.d.ts lybraries which I use. The typescript compiler use it information for import defenitions about js lybraries. The second case there reference are used is managing the order of ts files include into resulting js file. Another words if you add reference in file B.ts to A.ts in resulting js will be contains A.js first and B after. It's not often needed because TSC is smart and ordered file by types using but some times It's usefull then you use some suff from A.ts in B.ts dynamicly (not stronrly typed).



来源:https://stackoverflow.com/questions/36037962/how-to-get-rid-of-reference-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!