otomatiki muunganidzwa rokuponesa typescript mu Visual Studio Code

In this post isu huchagadzirisa matambudziko maviri: 1) murayiro “tsc” Hazvina kuzivikanwa Integrated chiteshi VS bumbiro, E 2) muunganidzwa hakushandi kungoerekana kana rokuponesa faira “.ts” (Nyorai Script).

ziviso

Just kuti contextualize, ari TypeScript Kunoitawo kuti kunyora bumbiro vachishandisa zvakasimba vataipa marongerwo uye bumbiro iri rakanyorwa kuti wakachena JavaScript. kare Visual Studio Code Zviri muchinjikwa-pakakwirira yekubvuma mupepeti akasikwa Microsoft.

// Versions akashandiswa Post ichi:
- Kutarisana Studio (VS) kodhi: mhando 1.14.1
- Typescript: mhando 2.4.1

Uyu nyore muromo, asi imi muve nematambudziko kana usingazivi zvauri kuita: nyaya yangu :D

Node.js uye typescript kugadzwa

Imwe nzira yokugadza ndiyo typescript kuburikidza Node.js pasuru maneja (ASL – Raiva pedyo nebundu pasuru maneja), asi kurishandisa, unofanira kutanga gadza kana Node.js.

Mushure kugadzwa zviri raiva pedyo nebundu, rakazaruka kana chiteshi (murayiro) uye kumhanya inotevera wokuti gadza kana typescript:

ASL gadza -d typescript

Kunyange zvazvo Windows Terminal (kana Linux), kuita bvunzo run pakati typescript pakuongorora yakaiswa shanduro. O murayiro “tsc” Inguva Acronym kuti typescript Compiler.

tsc -V

dambudziko

Dambudziko iri kuti murayiro “tsc” It raishanda anowanzoita muna Windows Terminal, asi kwete Integrated chinouraya anouya Visual Studio Code pachayo (VS kodhi), kuratidza kukanganisa anotevera:

'Tsc' haina kuzivikanwa sezvo ane zvemukati kana zvekunze murayiro,operable chirongwa kana batch mangé faira.

uyezve, Ndakanga ndisingadi kumhanya murayiro “tsc” zvose nguva Ndaida kuronga faira “.ts” (ekisitenjeni nokuti typescript). ndokubva, sezvo nguva dzose kuti otomatiki muunganidzwa kuponesa (Ctrl + S)? Izvi ndizvo zvatinofanira kuona.

zvimwe zvikanganiso

Achitamburira matambudziko aya, Posts ndikawana achiti kushandisa compileOnSave, asi izvi chete anotsigirwa Kutarisana Studio 2015 ru TypeScript> = 1.8.4 E atomu-typescript plugin. mune mamwe mazwi, hapana kushandiswa zvakanaka compileOnSave aihwa “tsconfig.json” kuita Visual Studio Code, bumbiro remitemo pazasi hakushande:

{
   "compileOnSave": zvechokwadi,
   "compilerOptions": {
       "noImplicitAny" : zvechokwadi
   }
}

mhinduro

TSC ari Integrated Terminal VS Code

Chokutanga tinofanira kupedza dambudziko tsc rirege kuzivikanwa Integrated inouraya iri Visual Studio Code (VS kodhi).

zvimwe Posts Ivo hunoratidza kuisa nzira tsk kana npm mugwara zvakatipoteredza shanduka, asi imwe nzira nyore yokugadzirisa ichi achiita kuisa “TypeScript nokuti Kutarisana Studio, izvo inowirirana kuti VS Code zvakare.

ikozvino ehe, pashure kugadzwa, abra O inouraya integrado kuita Visual Studio Code, Teclando:

// yokudimbudzira kiyi nokuti Integrated chinouraya ari Visual Studio Code:
Ctrl+`
// Dove kushandiswa O Menu a abrir O chinouraya hapana Visual Studio Code:
maonero > Integrated Terminal

Edza kuona shanduro typescript Vanotungamira revatema chiteshi VS Code (Kwete Windows Terminal), uye zvimwe kushanda:

tsc -V

otomatiki muunganidzwa kana kuchengetedza munhu faira .ts

Pakazosvika chinouraya VS Code ndiye nzvimbo kwenyu manyorero Directory (.ts), Somuenzaniso:

CD C:\wamp64  www  ts

Akasika faira tsconfig.json digitando hapana chirwere VS Code:

tsc --init

Ona kuti mumwe faira “tsconfig.json” Ngazvidyirwe kusikwa “C:\wamp64 www ts” (ano dhairetori).

Open kana tsconfig.json uye dzinoita kusarudza “sourceMap”: zvechokwadi, uye kuponesa shanduko, kuwana zvakanaka:

  "compilerOptions": {
    /* Basic Options */
    "target": "es5",                          /* Tsanangurai ECMAScript chipfuro shanduro: 'SS3' (kutyora chibvumirano), 'SS5', 'ES2015', 'ES2016', 'ES2017', kana 'ESNEXT'. */
    "module": "commonjs",                     /* Tsanangurai module Bumbiro chizvarwa: 'Commonjs', 'AMD', 'Maitiro', 'Umd', 'Es2015', kana 'ESNext'. */
    // "lib": [],                             /* Tsanangurai raibhurari mafaira kuti vanobatanidzwa muunganidzwa:  */
    // "allowJs": zvechokwadi,                       /* Bvumira JavaScript mafaira kuti rakanyorwa. */
    // "checkJs": zvechokwadi,                       /* Report zvikanganiso mu .js mafaira. */
    // "jsx": "preserve",                     /* Tsanangurai JSX Bumbiro chizvarwa: 'Tichengetedze', 'Sei-chizvarwa', kana 'sei'. */
    // "declaration": zvechokwadi,                   /* Zvinowanisa runoenzanirana '.d.ts' faira. */
    "sourceMap": zvechokwadi,                     /* Zvinowanisa runoenzanirana '.map' faira. */
    // "outFile": "./",                       /* Concatenate uye emit goho kuti kuroora faira. */
    // "outDir": "./",                        /* Redirect goho mamiriro kuti dhairetori. */
    // "rootDir": "./",                       /* Kutaridzwa mudzi Directory kuti chiyamuro mafaira. Shandisa kudzora goho Directory mamiriro pamwe --outDir. */
    ... anoenderera ...

nokukurumidza, Zvino iwe chete enda iri nechirwere vs Code uye kutaipa murayiro:

tsc -w

murayiro uyu ndiwo zvichiongororwa (kana uchiona, saka “w” of yokurinda) kushanda uye chero kuchinja mafaira .ts, kana I kunze, tichasimbiswawo pakarepo muunganidzwa .JS.

Ndizvo!

Uwandu kwakafanorongwa: 1117

Leave a Reply

kero email havazobvumirwi ichibudiswa. Raida minda anozivikanwa ne *