如何将visual studio代码语法高亮显示切换为typescript 2.0 beta?

时间:2016-07-22 15:16:40

标签: typescript visual-studio-code

我做到了 npm install -g typescript@beta npm install -i --save-dev typescript@beta

安装了业内人士打字稿visual studio代码。

之后我从他们的typescript 2.0声明中将以下行插入我的项目中,并且vscode将其强调为无效。

let foo: string | null = null;

如果重要,我的项目是使用ng new my-project创建的。

这里还有我的project.json文件和tslint.json文件

{
  "name": "portal-app",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "postinstall": "typings install",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "2.0.0-rc.3",
    "@angular/compiler": "2.0.0-rc.3",
    "@angular/core": "2.0.0-rc.3",
    "@angular/forms": "0.2.0",
    "@angular/http": "2.0.0-rc.3",
    "@angular/platform-browser": "2.0.0-rc.3",
    "@angular/platform-browser-dynamic": "2.0.0-rc.3",
    "@angular/router": "3.0.0-alpha.8",
    "es6-shim": "0.35.1",
    "ng2-bootstrap": "^1.0.20",
    "reflect-metadata": "0.1.3",
    "rx-socket-subject": "^0.7.0",
    "rxjs": "5.0.0-beta.6",
    "systemjs": "0.19.26",
    "zone.js": "0.6.12"
  },
  "devDependencies": {
    "angular-cli": "1.0.0-beta.9",
    "codelyzer": "0.0.20",
    "ember-cli-inject-live-reload": "1.4.0",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "0.13.22",
    "karma-chrome-launcher": "0.2.3",
    "karma-jasmine": "0.3.8",
    "protractor": "3.3.0",
    "ts-node": "0.5.5",
    "tslint": "3.11.0",
    "typescript": "^2.0.0",
    "typings": "0.8.1"
  }
}

tslint.json

{
  "rulesDirectory": [
    "node_modules/codelyzer"
  ],
  "rules": {
    "class-name": true,
    "comment-format": [
      true,
      "check-space"
    ],
    "curly": true,
    "eofline": true,
    "forin": true,
    "indent": [
      true,
      "spaces"
    ],
    "label-position": true,
    "label-undefined": true,
    "max-line-length": [
      true,
      140
    ],
    "member-access": false,
    "member-ordering": [
      true,
      "static-before-instance",
      "variables-before-functions"
    ],
    "no-arg": true,
    "no-bitwise": true,
    "no-console": [
      true,
      "debug",
      "info",
      "time",
      "timeEnd",
      "trace"
    ],
    "no-construct": true,
    "no-debugger": true,
    "no-duplicate-key": true,
    "no-duplicate-variable": true,
    "no-empty": false,
    "no-eval": true,
    "no-inferrable-types": true,
    "no-shadowed-variable": true,
    "no-string-literal": false,
    "no-switch-case-fall-through": true,
    "no-trailing-whitespace": true,
    "no-unused-expression": true,
    "no-unused-variable": true,
    "no-unreachable": true,
    "no-use-before-declare": true,
    "no-var-keyword": true,
    "object-literal-sort-keys": false,
    "one-line": [
      true,
      "check-open-brace",
      "check-catch",
      "check-else",
      "check-whitespace"
    ],
    "quotemark": [
      true,
      "single"
    ],
    "radix": true,
    "semicolon": [
      "always"
    ],
    "triple-equals": [
      true,
      "allow-null-check"
    ],
    "typedef-whitespace": [
      true,
      {
        "call-signature": "nospace",
        "index-signature": "nospace",
        "parameter": "nospace",
        "property-declaration": "nospace",
        "variable-declaration": "nospace"
      }
    ],
    "variable-name": false,
    "whitespace": [
      true,
      "check-branch",
      "check-decl",
      "check-operator",
      "check-separator",
      "check-type"
    ],

    "directive-selector-name": [true, "camelCase"],
    "component-selector-name": [true, "kebab-case"],
    "directive-selector-type": [true, "attribute"],
    "component-selector-type": [true, "element"],
    "use-input-property-decorator": true,
    "use-output-property-decorator": true,
    "use-host-property-decorator": true,
    "no-input-rename": true,
    "no-output-rename": true,
    "use-life-cycle-interface": true,
    "use-pipe-transform-interface": true,
    "component-class-suffix": true,
    "directive-class-suffix": true
  }
}

3 个答案:

答案 0 :(得分:8)

我找到了一个有方向的地方(链接如下)。

摘要:
ctrl + shift + p - >输入用户设置

添加以下行,更改tsc 2.0在您的计算机上所在的路径。

"typescript.tsdk": "c:\\users\\mmeisberger\\AppData\\Roaming\\npm\\node_modules\\typescript\\lib"

重新启动IDE。

官方指示:
https://code.visualstudio.com/Docs/languages/typescript#_using-newer-typescript-versions

答案 1 :(得分:1)

  

visual studio代码语法突出显示为typescript 2.0 beta

VSCode不使用typescript来提供语法突出显示。它实际上使用textmate,其中包含少数错误:https://github.com/Microsoft/TypeScript-TmLanguage/issues

更多

alm支持ts 2开箱即用npm install alm -g实际上使用TypeScript编译器提供突出显示... Not Text Mate

答案 2 :(得分:0)

如果您使用的是Mac,则可以按npm install typescript@2.0 -g安装 typescript 2.0 以供全局使用。然后,键入npm list typescript -g以显示路径:

$ npm list typescript -g
/usr/local/lib
└── typescript@2.0.3

您会发现命令tsctsserver应位于/usr/local/lib/node_modules/typescript/lib路径中。

现在,打开 Virtual Studio代码cmd + ,)的偏好设置,并将以下内容添加到settings.json

{
  ...,
  "typescript.tsdk": "/usr/local/lib/node_modules/typescript/lib"
}

重新启动 Virtual Studio代码,并打开一个TypeScript文件,现在它应该将TS代码突出显示为2.x