VS 2015 MVC项目中来自Angular和Typescript的编译错误 [英] Compilation error from Angular and typescript in VS 2015 MVC project
问题描述
我是Angular的新手,正在迈出第一步在 ASP.Net
MVC项目中实现.我从github下载了Angular快速入门,并为Visual Studio 2015 Update 3下载了最新的打字稿 v 3.2.2.0 .我收到以下错误:主题无法分配给相同的属性"中的属性提升基本类型可观察".
I am new to Angular and taking baby step to implement in ASP.Net
MVC project. I downloaded the Angular quick start from github and latest typescript v 3.2.2.0 for visual studio 2015 update 3. I am getting the following error Property lift in the type 'Subject is not assignable tot he same property in base type Observable' .
other version used:
npm -v is 6.4.1
node -v is 10.15.2
我从github下载的package.json引用了旧版本.附件是我正在使用的 package.json
文件.
The package.json that I downloaded from github had a reference to the older version version. Attached is the package.json
file i am using.
我的 npm
正在运行,并且能够通过Lift-server托管网站.
I have my npm
running and was able to host the website through lift-server.
错误TS2416:主题"类型中的属性提升"不可分配基本类型为可观察"的相同属性.输入'(运算符:运算符)=>可观察"不能分配给类型'(运算符:运算符)=>可观察的'.输入可观察"不可分配给可观察"类型.类型"T"不可分配键入"R"
error TS2416: Property 'lift' in type 'Subject' is not assignable to the same property in base type 'Observable'. Type '(operator: Operator) => Observable' is not assignable to type '(operator: Operator) => Observable'. Type 'Observable' is not assignable to type 'Observable'. Type 'T' is not assignable to type 'R'
请帮助.
{
"name": "angular-quickstart",
"version": "1.0.0",
"description": "QuickStart package.json from the documentation, supplemented with testing support",
"scripts": {
"build": "tsc -p src/",
"build:watch": "tsc -p src/ -w",
"build:e2e": "tsc -p e2e/",
"serve": "lite-server -c=bs-config.json",
"serve:e2e": "lite-server -c=bs-config.e2e.json",
"prestart": "npm run build",
"start": "concurrently \"npm run build:watch\" \"npm run serve\"",
"pree2e": "npm run build:e2e",
"e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first",
"preprotractor": "webdriver-manager update",
"protractor": "protractor protractor.config.js",
"pretest": "npm run build",
"test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
"pretest:once": "npm run build",
"test:once": "karma start karma.conf.js --single-run",
"lint": "tslint ./src/**/*.ts -t verbose"
},
"keywords": [],
"author": "",
"license": "MIT",
"dependencies": {
"@angular/common": "~4.3.4",
"@angular/compiler": "~4.3.4",
"@angular/core": "~4.3.4",
"@angular/forms": "~4.3.4",
"@angular/http": "~4.3.4",
"@angular/platform-browser": "~4.3.4",
"@angular/platform-browser-dynamic": "~4.3.4",
"@angular/router": "~4.3.4",
"angular-in-memory-web-api": "~0.3.0",
"systemjs": "0.19.40",
"core-js": "^2.4.1",
"rxjs": "5.0.1",
"zone.js": "^0.8.4"
},
"devDependencies": {
"concurrently": "^3.2.0",
"lite-server": "^2.2.2",
"typescript": "~2.1.0",
"canonical-path": "0.0.2",
"tslint": "^3.15.1",
"lodash": "^4.16.4",
"jasmine-core": "~2.4.1",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~4.0.14",
"rimraf": "^2.5.4",
"@types/node": "^6.0.46",
"@types/jasmine": "2.5.36"
},
"repository": {}
}
推荐答案
这里有几处错误.
首先,您的打字稿是最新版本.我不确定Angular 7是否支持Typescript 3.2.2.我认为他们将在Angular 8即将发布时发布.其次,您的Angular软件包已过时.如果可能,您应该更新到Angular7.
第三,Visual Studio有时会对您的ts配置感到挑剔.如果以上两个都不起作用,请发布您的ts配置,以便我们进行查看.我从VS 2017中的Web表单模板构建Angular应用程序.我使用Angular CLI而不是任何VS Extension.如果您需要更多详细信息,请告诉我.
There are a couple things wrong here.
First, your Typescript is on the latest version. I'm not sure even Angular 7 supports Typescript 3.2.2. I think they will when Angular 8 is released shortly.
Second, your Angular packages are way out of date. You should update to Angular 7 if possible.
Third, Visual Studio can sometimes get picky about your ts config. If the above two don't work please post your ts config so we can look at it. I build Angular Applications from the Web Form template in VS 2017. I use the Angular CLI instead of any VS Extension. If you want more details let me know.
这是我最近启动的项目中的package.json:
Here's a package.json from a project I started recently:
"private": true,
"dependencies": {
"@angular/animations": "~7.1.0",
"@angular/common": "~7.1.0",
"@angular/compiler": "~7.1.0",
"@angular/core": "~7.1.0",
"@angular/forms": "~7.1.0",
"@angular/platform-browser": "~7.1.0",
"@angular/platform-browser-dynamic": "~7.1.0",
"@angular/router": "~7.1.0",
"classlist.js": "^1.1.20150312",
"core-js": "^2.5.4",
"d3": "^4.10.2",
"d3-array": "^1.2.1",
"d3-brush": "^1.0.4",
"d3-color": "^1.0.3",
"d3-force": "^1.1.0",
"d3-format": "^1.2.0",
"d3-hierarchy": "^1.1.5",
"d3-interpolate": "^1.1.5",
"d3-scale": "^1.0.6",
"d3-selection": "^1.1.0",
"d3-shape": "^1.2.0",
"d3-time-format": "^2.1.0",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"web-animations-js": "^2.3.1",
"zone.js": "~0.8.26",
"bootstrap": "4.3.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.11.0",
"@angular-devkit/build-ng-packagr": "~0.11.0",
"@angular/cli": "~7.1.3",
"@angular/compiler-cli": "~7.1.0",
"@angular/language-service": "~7.1.0",
"@types/node": "~8.9.4",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.1.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"ng-packagr": "^4.2.0",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tsickle": ">=0.29.0",
"tslib": "^1.9.0",
"tslint": "~5.11.0",
"typescript": "~3.1.6"
}
}
这篇关于VS 2015 MVC项目中来自Angular和Typescript的编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!