Angular 角度2打字错误
我已经在angular 2站点上完成了快速启动。我正在尝试获取gulpfile设置属性,以便在Visual Studio aspnetcore项目中传输我的类型脚本。我使用的是typescript 1.8.10,而不是2.0测试版,该测试版在其他地方发布了解决方案 在运行“ts2”任务时,我遇到了其中70个错误: c:/path/to/my/project/Quickstart/node_modules/@angular/common/src/pipes/async_pipe.d.ts(41,38):错误TS2304:找不到名称“Promise”。 c:/path/to/my/project/Quickstart/node_modules/@angular/compiler/src/compile_metadata.d.ts(347,20):错误TS2304:找不到名称“Set”。 c:/path/to/my/project/Quickstart/node_modules/@angular/compiler/src/compile_metadata.d.ts(348,15):错误TS2304:找不到名称“Set”。 c:/path/to/my/project/Quickstart/node_modules/@angular/compiler/src/directive_normalizer.d.ts(19100):错误TS2304:找不到名称“Promise” My Gulpfile.js:Angular 角度2打字错误,angular,typescript,gulp,asp.net-core-1.0,Angular,Typescript,Gulp,Asp.net Core 1.0,我已经在angular 2站点上完成了快速启动。我正在尝试获取gulpfile设置属性,以便在Visual Studio aspnetcore项目中传输我的类型脚本。我使用的是typescript 1.8.10,而不是2.0测试版,该测试版在其他地方发布了解决方案 在运行“ts2”任务时,我遇到了其中70个错误: c:/path/to/my/project/Quickstart/node_modules/@angular/common/src/pipes/async_pipe.d.ts(41,3
var ts = require("gulp-typescript");
var gulp = require('gulp');
var clean = require("gulp-clean");
// Delete the dist directory
gulp.task("clean", function () {
return gulp.src(destPath)
.pipe(clean());
});
gulp.task("scriptsNStyles", () => {
gulp.src([
"core-js/client/**",
"systemjs/dist/system.src.js",
"reflect-metadata/**",
"rxjs/**",
"zone.js/dist/**",
"@angular/**",
"jquery/dist/jquery.*js"
], {
cwd: "node_modules/**"
})
.pipe(gulp.dest("./wwwroot/lib"));
});
var tsProject = ts.createProject("./tsconfig.json");
gulp.task("ts", function (done) {
//var tsResult = tsProject.src()
var paths = {
scripts: ['./wwwroot/app/*.ts']
};
gulp.src(paths.scripts).pipe(gulp.dest('wwwroot/app'));
});
gulp.task('ts2', function (done) {
var tsResult = gulp.src([
"wwwroot/app/*.ts"
])
.pipe(ts(tsProject), undefined, ts.reporter.fullReporter());
return tsResult.js.pipe(gulp.dest('./wwwroot/app'));
});
gulp.task("watch", ["watch.ts"]);
gulp.task("watch.ts", ["ts"], function () {
return gulp.watch("./wwwroot/app/*.ts", ["ts"]);
});
gulp.task("default", ["scriptsNStyles", "watch"]);
tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"typings/index",
"typings/index.d.ts",
"wwwroot/lib"
],
"compileOnSave": true
}
package.json:
{
"version": "1.0.0",
"name": "asp.net",
"scripts": {
"postinstall": "typings install",
"typings": "typings"
},
"private": true,
"dependencies": {
"@angular/common": "2.0.0-rc.7",
"@angular/compiler": "2.0.0-rc.7",
"@angular/compiler-cli": "0.6.1",
"@angular/core": "2.0.0-rc.7",
"@angular/forms": "2.0.0-rc.7",
"@angular/http": "2.0.0-rc.7",
"@angular/platform-browser": "2.0.0-rc.7",
"@angular/platform-browser-dynamic": "2.0.0-rc.7",
"@angular/router": "3.0.0-rc.3",
"@angular/upgrade": "2.0.0-rc.7",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.27",
"zone.js": "^0.6.21",
"angular2-in-memory-web-api": "0.0.19",
"bootstrap": "^3.3.6"
},
"devDependencies": {
"typescript": "^1.8.10",
"gulp": "^3.9.1",
"path": "^0.12.7",
"gulp-clean": "^0.3.2",
"gulp-concat": "^2.6.0",
"gulp-typescript": "^2.13.6",
"typings": "^1.3.1",
"gulp-tsc": "^1.2.0"
}
}
Typings.json:
{
"globalDependencies": {
"core-js": "registry:dt/core-js#0.0.0+20160602141332",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
"node": "registry:dt/node#6.0.0+20160621231320"
}
}
透明看起来很有效,但我不喜欢这些错误。如何解决此问题?Typescript 2.0以后的版本将不推荐使用打字。一个更简单的解决方案是使用npm类型定义包。我知道你要求的是1.8解决方案,但我的强烈建议是现在就删除打字
- 从Microsoft下载Typescript 2.0.2或更高版本。或从npm安装:
npm安装-g typescript
- 将以下行添加到package.json文件
“@types/jasmine”:“^2.2.33”、和“@types/core js”:“^0.9.32”、
或使用命令行:“@types/node”:“^6.0.38”、
npm install@types/core js@types/jasmin@types/node--save dev
- 在tsconfig.json文件中添加以下内容:
"typeRoots": [
"node_modules/@types"
],
"types": [
"core-js",
"jasmine",
"node"
]
核心js类型定义将消除您的承诺并设置定义错误
在typescript 2.0中,类型定义更易于使用。您需要通过相同的过程来获取lodash、d3或任何其他想要使用的js库的定义。你可以用打字机打字。请在Microsoft的博客上阅读更多信息:
您需要将devdependency更新为“typescript”:“^2.0.2”。或npm安装类型脚本--保存开发
要更新gulpfile以使用最新版本的typescript,请将tsProject行更改为:
var tsProject = ts.createProject('tsconfig.json', {
typescript: require('typescript')
});
有关更多信息,请参阅。打字机在Typescript 2.0以后的版本中将不推荐使用。一个更简单的解决方案是使用npm类型定义包。我知道你要求的是1.8解决方案,但我的强烈建议是现在就删除打字
- 从Microsoft下载Typescript 2.0.2或更高版本。或从npm安装:
npm安装-g typescript
- 将以下行添加到package.json文件
“@types/core js”:“^0.9.32”、
“@types/jasmine”:“^2.2.33”、
和“@types/node”:“^6.0.38”、
或使用命令行:npm install@types/core js@types/jasmin@types/node--save dev
在tsconfig.json文件中添加以下内容:
tsconfig.json
"typeRoots": [
"node_modules/@types"
],
"types": [
"core-js",
"jasmine",
"node"
]
核心js类型定义将消除您的承诺并设置定义错误
在typescript 2.0中,类型定义更易于使用。您需要通过相同的过程来获取lodash、d3或任何其他想要使用的js库的定义。你可以用打字机打字。请在Microsoft的博客上阅读更多信息:
您需要将devdependency更新为“typescript”:“^2.0.2”。或npm安装类型脚本--保存开发
要更新gulpfile以使用最新版本的typescript,请将tsProject行更改为:
var tsProject = ts.createProject('tsconfig.json', {
typescript: require('typescript')
});
有关更多信息,请参见。尝试将tsconfig.json
的编译器选项
目标
属性更新为“es6”,因为集合和承诺仅在es6中可用
{
"compilerOptions": {
"target": "es6",
...
}
尝试将tsconfig.json
的编译器选项
目标
属性更新为“es6”,因为集合和承诺仅在es6中可用
{
"compilerOptions": {
"target": "es6",
...
}
这是找不到类型的问题。这里有一个类似的问题。看起来你可能需要核心js
类型扫描你的打字代码。json?我在公司代理/过滤器后面遇到过这个问题。在我的例子中,由于必须通过SSL访问,无法安装打字。如果你发现这是一个问题,我可以解释如何绕过它。尽管这里有许多问题可以解决这个问题。@Krisholenbeck更新为包含打字。json@KrisHollenbeck我的devdependency部分引用了TypeScript 1.8.10这是找不到类型的问题。这里有一个类似的问题。看起来你可能需要核心js
类型扫描你的打字代码。json?我在公司代理/过滤器后面遇到过这个问题。在我的例子中,由于必须通过SSL访问,无法安装打字。如果你发现这是一个问题,我可以解释如何绕过它。尽管这里有许多问题可以解决这个问题。@Krisholenbeck更新为包含打字。json@KrisHollenbeck我的devdependency部分引用了TypeScript 1.8.10,我将尝试一下。我需要对packages.json文件的devdependences部分进行任何更改吗?需要。您需要将devdependency更新为2.0.2,并对gulpfile.js做一些小的更改。我会用更多信息更新答案。我会试试这个。我需要对packages.json文件的devdependences部分进行任何更改吗?需要。您需要将devdependency更新为2.0.2,并对gulpfile.js做一些小的更改。我用更多信息更新答案。