gpt4 book ai didi

angular - 即使 tsc 版本足够高,带有 bang 运算符的 Typescript 文件也不会构建

转载 作者:搜寻专家 更新时间:2023-10-30 21:45:44 30 4
gpt4 key购买 nike

我有一个带有这个文件的 angular 4 项目

class DemoClass {
description!: string;
}

如果我用

构建它
ng build

从我得到的项目根

ERROR in src/app/client/medisoft-client.ts(3,16): error TS1005: '=' expected. src/app/client/medisoft-client.ts(3,17): error TS1109: Expression expected.

删除 bang 运算符可以解决这个问题,所以这肯定是问题所在。错误似乎是类型脚本的版本不够高但是如果我运行

tsc --version

我明白了

Version 3.3.4000

足以支持 bang 运算符。如果我转到包含该文件的目录并只转换该文件,即移动,即

tsc --out test.js test.ts

然后它构建正常,我得到了 js 输出

所以看起来 angular 使用的是旧版本的 typescript ,但我不知道现在该去哪里解决这个问题

Package.json文件是

{   "name": "project-name",   "version": "0.0.0",   "license": "MIT",  "scripts": {
"ng": "ng",
"start": "ng build --base-href /Angular --deploy-url /Angular/",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e" }, "private": true, "dependencies": {
"@angular/animations": "^5.2.0",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/router": "^5.2.0",
"core-js": "^2.4.1",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19" }, "devDependencies": {
"@angular/cli": "1.6.5",
"@angular/compiler-cli": "^5.2.0",
"@angular/language-service": "^5.2.0",
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "^2.9.2" } }

最佳答案

您的 Angular 项目 typescript 版本低于您的全局版本。所以你需要像下面这样在你的 Angular 项目中安装更新版本

npm install typescript@3.3.4000 --save-dev

希望这会有所帮助!

关于angular - 即使 tsc 版本足够高,带有 bang 运算符的 Typescript 文件也不会构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55391164/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com