简体   繁体   English

组合js文件时Typescript Intellisense无法正常工作

[英]Typescript Intellisense not working when combining js files

I found the TypeScript Build tab in the properties of a typescript project. 我在打字稿项目的属性中找到“打字稿生成”选项卡。 And on that tab was an interesting feature called: 'Combine JavaScript output into file: '. 在该选项卡上有一个有趣的功能,称为:“将JavaScript输出合并到文件:”。 This seems to work like intended but it seems to mess up intellisense for some reason. 这似乎按预期工作,但由于某种原因似乎使智能感知混乱。

When the option to combine the js output files is on, intellisense stops working (ctrl+space doesn't do anything). 当组合js输出文件的选项打开时,intellisense停止工作 (ctrl + space不执行任何操作)。 But syntax highlighting, building, and refactoring still works. 但是语法高亮显示,构建和重构仍然有效。 It does this until the option is turned off and VS has restarted. 它将执行此操作,直到关闭该选项并且VS重新启动为止。

I installed the Visual Studio 2013 Update 2 CTP 2 and removed the original typescript plugin (because it's included in the update?). 我安装了Visual Studio 2013 Update 2 CTP 2,并删除了原始的打字稿插件(因为它包含在更新中?)。 Web Essentials is enabled, it doesn't crash any more with the new update, and disabling it doesn't fix the intellisense. Web Essentials已启用,它不会随着新更新而崩溃,并且禁用它也无法解决智能感知。

What is going on? 到底是怎么回事? How do I get this to work? 我该如何工作?

For what it's worth, this issue seems to be solved in newer versions of typescript. 值得一提的是,此问题似乎已在较新的打字稿版本中解决。 What version of typescript are you using? 您正在使用什么版本的打字稿?

If you can't upgrade your typescript version, does using something outside of the built in single file output work for you? 如果您无法升级打字稿版本,那么使用内置的单个文件输出之外的功能对您有用吗? If so, you should look into using grunt-ts-bundle . 如果是这样,您应该考虑使用grunt-ts-bundle

grunt.initConfig({
  bundle: {
    main: {
        rootModule: 'plat',
        license: './license.txt',
        version: '<%= pkg.version %>',
        src: './index.html',
        dest: [
            './out.ts'
        ],
        preSave: function (data, done) {
            done(data);
        }
    }
  }
});

grunt.loadNpmTasks('grunt-ts-bundle');

This is just a grunt task for running ts-bundle: 这只是运行ts-bundle的艰巨任务:

https://github.com/Platypi/ts-bundle https://github.com/Platypi/ts-bundle

Then you can wrap files in your src (`./index.html) like this: 然后可以将文件包装在src(`./index.html)中,如下所示:

<!-- ts-bundle-start -->
<script src="app/models/user.model.js"></script>
<script src="app/controllers/users.controller.js"></script>
<!-- ts-bundle-end -->

This would combine your user.model.js and users.controller.js file into one out.js file. 这会结合您的user.model.jsusers.controller.js文件分割成一个out.js文件。

If this does work for you and you have any other questions or need clarification just let me know - Good luck! 如果这对您有用,并且您还有其他问题或需要澄清的话,请告诉我-祝您好运!

I ran into similar issues with Typescript and VS2013 and different versions of typescript. 我遇到了Typescript和VS2013以及不同版本的Typescript的类似问题。 I had stayed with older, . 我和年纪大的人呆在一起。 95, of typescript for quite some time to avoid this issue. 95,打字稿在相当长的时间内避免了这个问题。

I am happy to report that this issue has gone away with the most recent builds of the ts plugin. 我很高兴地报告,ts插件的最新版本已解决了该问题。

Combine into one file, compile on save and intellisense all now work together for me. 合并到一个文件中,在保存时编译并智能感知,所有这些现在都可以为我工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM