Làm thế nào để chuyển đổi đánh dấu cú pháp Visual Studio Code sang TypeScript 2.0 beta?
Tôi đã thực hiện npm install -g typescript@beta npm install -i --save-dev typescript@beta
đã cài đặt loại TypeScript dành cho những người nội bộ trên Visual Studio Code.
Sau đó tôi chèn dòng sau vào dự án của mình từ thông báo TypeScript 2.0 của họ và VSCode đánh dấu nó là không hợp lệ.
let foo: string | null = null;Nếu quan trọng thì dự án của tôi được tạo bằng ng new my-project.
Ngoài ra đây là tệp project.json và tệp tslint.json của tôi
{
"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
}
}
Câu trả lời #1
Tôi tìm thấy một nơi có chỉ dẫn (liên kết bên dưới).
Tóm tắt:
ctrl+shift+p -> gõ cài đặt người dùng
thêm dòng sau và thay đổi đường dẫn đến nơi tsc 2.0 nằm trên máy của bạn.
"typescript.tsdk": "c:\\users\\mmeisberger\\AppData\\Roaming\\npm\\node_modules\\typescript\\lib"Khởi động lại IDE của bạn.
Hướng dẫn chính thức ở đây:
https://code.visualstudio.com/Docs/languages/typescript#_using-newer-typescript-versions
Câu trả lời #2
tô sáng cú pháp Visual Studio Code cho TypeScript 2.0 beta
VSCode không sử dụng typescript để cung cấp nhận diện cú pháp. Thực ra nó sử dụng textmate và có một vài lỗi nhỏ : https://github.com/Microsoft/TypeScript-TmLanguage/issues
Thêm
alm hỗ trợ ts 2 ngay khi cài đặt npm install alm -g Và thực sự sử dụng trình biên dịch TypeScript để cung cấp việc tô sáng ... Không phải Text Mate 🌹