简体   繁体   English

如何使用vs2017rc创建Aurelia打字稿项目

[英]How to create aurelia typescript project with vs2017rc

I am new to aurelia, and I need create a prototype project of the framework. 我是aurelia的新手,我需要创建框架的原型项目。 At the beginning, I planed to use skeleton-typescript-aspnetcore skeleton, but when I tried the vs2017rc, I found it uses .csproj as the default format(while vs2015 is project.json/.xproj), I think we should follow the vs2017 because we will upgrade our IDE after it's been launched. 一开始,我计划使用skeleton-typescript-aspnetcore框架,但是当我尝试使用vs2017rc时,我发现它使用.csproj作为默认格式(而vs2015是project.json / .xproj),我认为我们应该遵循vs2017,因为我们将在IDE启动后对其进行升级。

The vs2017 have a wizard to upgrade .xproj project, but after the upgrading(skeleton-typescript-aspnetcore), there still lots of error ahead me... vs2017有一个升级.xproj项目的向导,但是升级之后(skeleton-typescript-aspnetcore),我面前仍然有很多错误...

I also tried aurelia-cli, but seems it has not support vs2017 yet, does anyone could give a guide to create the prototype project? 我也尝试过aurelia-cli,但是似乎它还不支持vs2017,有人可以指导创建原型项目吗? I will integrate some plugins like the skeleton mentioned above, such as gulp,karma,breeze... 我将集成一些插件,例如上面提到的骨架,例如gulp,karma,breeze ...

thank you in advance. 先感谢您。

Since Visual Studio 2017 just launched I thought I'd answer how I solved this, as there are still many errors when using "skeleton-typescript-aspnetcore". 自从Visual Studio 2017刚刚启动以来,我想我会回答如何解决此问题,因为在使用“ skeleton-typescript-aspnetcore”时仍然存在许多错误。

Using https://github.com/aurelia/skeleton-navigation/releases/tag/1.1.2 as a starting point, these are the steps to get it running: https://github.com/aurelia/skeleton-navigation/releases/tag/1.1.2作为起点,以下是使其运行的步骤:

When you first run the project you will get errors complaining that some files located in /test/ is not under 'rootDir'. 首次运行项目时,您会得到错误消息,提示/ test /中的某些文件不在'rootDir'下。 In your tsconfig.json the rootDir is defined as "src/", this can be solved simply by moving your test folder inside your src folder. 在tsconfig.json中,将rootDir定义为“ src /”,只需将您的测试文件夹移到src文件夹中即可解决。 This will cause new errors because the paths defined in those files has now changed. 这将导致新的错误,因为这些文件中定义的路径现已更改。 You will need to edit app, child-router and users imports like this: import {Users} from '../../users'; 您将需要编辑应用,子路由器和用户导入,如下所示: import {Users} from '../../users'; IntelliSense should help you out here. IntelliSense应该可以帮助您。

The command gulp test will also not run before changing to the new path, you can change the path in karma.conf.js: 在更改为新路径之前,也不会运行命令gulp test ,您可以在karma.conf.js中更改路径:

files: [
  'src/test/unit/setup.ts',
  'src/test/unit/*.ts'
],

Next the file users.ts will throw errors like Type 'Response' is not assignable to type 'any[]' . 接下来,文件users.ts将引发错误,例如Type 'Response' is not assignable to type 'any[]' You will need to tell TypeScript what you're declaring like this: public users : Object = []; 您需要像这样告诉TypeScript您声明的内容: public users : Object = []; or simply: public users = {}; 或者简单地说: public users = {};

The final problem is that you're going to have a lot of duplicate identifier errors, at the time of writing this the cause of this seems to be from the changes brought on by TypeScript version 2.2.1. 最终的问题是,您将有很多重复的标识符错误,在撰写本文时,原因似乎是来自TypeScript 2.2.1版带来的更改。 I don't know what specifically breaks, but I know that previous version 2.1.5 still works. 我不知道具体中断了什么,但我知道以前的版本2.1.5仍然有效。 So what you need to do is to run npm install typescript@2.1.5 --save in your src/skeleton directory, the --save is just to update your package.json file, you can do this on your own later as well if you wish. 因此,您需要做的是在src / skeleton目录中运行npm install typescript@2.1.5 --save ,--save只是更新package.json文件,您以后也可以自行执行此操作如果你希望。

After you've done that your gulp errors (20~ of them) should be resolved. 完成之后,应该解决您的gulp错误(其中20%)。 But there are still some errors remaining caused by duplicate signatures. 但是仍然存在由于重复签名导致的一些错误。 Again, things have changed in TypeScript 2.0+, there is now a simplified way of getting and using declaration files. 同样,TypeScript 2.0+中的情况已经发生了变化,现在有了获取和使用声明文件的简化方法。 Here is an answer on SO on how to use the @types feature: How should I use @types with TypeScript 2 , but to keep this short and sweet you will have to go to your tsconfig.json file and explicitly tell where to find the @types/node folder. 这是关于如何使用@types功能的SO答案: 我应该如何在TypeScript 2中使用@types ,但是为了简短易懂,您必须转到tsconfig.json文件,并明确告诉在哪里找到@ types / node文件夹。 It would look something like this: 它看起来像这样:

"compilerOptions": {
...
"typeRoots": [
   "node_modules/@types"
],
"types": [ "node" ]
...
},

Hope this helps, with these changes the project should now build and launch correctly. 希望这会有所帮助,通过这些更改,项目现在应该可以正确构建和启动。

EDIT: I recently ran into some problems again with building my project. 编辑:最近我在构建项目时又遇到了一些问题。 I got a lot of duplicate identifiers again... I however ran across this answer on SO: TypeScript throws multiple duplicate identifiers 我又得到了很多重复的标识符...但是我在SO上遇到了这个答案: TypeScript抛出多个重复的标识符

Apparently TypeScript latest ships with fetch definitions out of the box, so I was able to run the command from the answer in the link: 显然TypeScript是最新提供的,具有开箱即用的定义,因此我能够从链接中的答案运行命令:

npm uninstall @types/whatwg-fetch

And upgrading from typescript 2.1.5 to latest: 并从打字稿2.1.5升级到最新版本:

npm install typescript --save

You might even want to install typescript globally by appending -g . 您甚至可能想通过附加-g全局安装typescript。 Also this will continue to be an issue unless you comment out/delete url and whatwg-fetch from typings.json globalDependencies in order to prevent it from recreating itself: 另外,除非您注释掉/删除urls和whatwg- typings.json来自typings.json globalDependencies,以防止其重新创建自身,否则这将继续是一个问题:

 "globalDependencies": {
    //"url": "github:aurelia/fetch-client/doc/url.d.ts#bbe0777ef710d889a05759a65fa2c9c3865fc618",
    //"whatwg-fetch": "registry:dt/whatwg-fetch#0.0.0+20160524142046"
  }

Then you can either delete the typings folder, running typings install again or edit index.d.ts in the typings folder and delete the reference paths to whatwg-fetch and url. 然后,您可以删除打字文件夹,再次运行打字typings install ,或者在打字文件夹中编辑index.d.ts并删除whatwg-fetch和url的引用路径。 Hope this helps someone who might've encountered the same problems even after "fixing" it. 希望这对即使“修复”后仍可能遇到相同问题的人有所帮助。

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

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