atom-typescript找不到类型 [英] atom-typescript can not find typings

查看:140
本文介绍了atom-typescript找不到类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用atom-typescript在Atom中配置了一个新的Angular/Typescript项目.该项目设置为具有一个主要的角度模块文件,该文件可导入所有模块,包括类型定义文件.一切都可以在gulp中编译,并且没有问题.

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.

由于我使用的是gulp,因此我已将atom-typescript配置为在保存时不编译.ts文件.现在,我在我的所有.ts文件中看到错误,表明原子打字机皮棉机找不到类型.

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.

例如:Module 'ng' has no exported member 'IScope' at line 1 col 32

我知道我可以通过向每个ts文件(如/// <reference path="../../.tmp/typings/tsd.d.ts" />)添加引用路径来解决此问题,但这似乎确实多余且不必要.

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.

由于atom-typescript会引发这些错误,我有什么办法可以在整个项目的设置中将我的类型定义文件的位置设置为某个位置?还有其他有关如何处理此问题的建议吗?

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?

推荐答案

将键入内容与files条目中的其他ts文件一起放入tsconfig.json文件中.

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"
    ]
...
}

files条目将自动更新.

修改

由于Typescript现在已正式支持此功能,因此(跨IDE)更可移植的解决方案可能是使用tsconfigexclude属性.

Since this is now officially supported by Typescript, a more portable solution (across IDEs) may be to use the exclude property of tsconfig.

反之亦然:编译所有排除的内容(通常是node_modules下的任何内容,以及public中的静态资产)

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"
    ]
}

链接

这篇关于atom-typescript找不到类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆