问题
I just configured a new Angular/Typescript project in Atom using atom-typescript. The project is set up to have a main angular module file that imports all of the modules, including the type definition files. Everything compiles in gulp and runs no problem.
Since I'm using gulp, I've configured atom-typescript to not compile the .ts files on save. Now, I'm seeing errors in all of my .ts files showing that the atom-typescript linter cannot find the typings.
Ex: Module 'ng' has no exported member 'IScope' at line 1 col 32
I know that I can probably solve this problem by adding a reference path to each of my ts files like /// <reference path="../../.tmp/typings/tsd.d.ts" />
, but that seems really redundant and unnecessary.
Since these errors are being raised by atom-typescript, is there any way that I can set the location of my type definition files somewhere in the settings for the whole project? Any other suggestions for how to handle this?
回答1:
Put the typings in the tsconfig.json
file along with the other ts files in the files
entry.
Since you are using atom-typescript, you can even use glob patterns, i.e.
{
...
"filesGlob": [
"./typescript/**/*.ts",
"./typescript/**/*.tsx",
"./typings/**/*.d.ts"
]
...
}
The files
entry will be automatically updated.
Edit
Since this is now officially supported by Typescript, a more portable solution (across IDEs) may be to use the exclude
property of tsconfig
.
This works the other other way round: compile everything but what is excluded (typically anything under node_modules
and the static assets in, says, public
)
{
"compilerOptions": {
...
},
"exclude": [
"node_modules",
"public"
]
}
Official details at this link
来源:https://stackoverflow.com/questions/34271914/atom-typescript-can-not-find-typings