atomatik tari saving typescript a Kayayyakin aikin hurumin Code

A wannan post za mu warware matsalolin biyu: 1) umurnin “tsk” An ba a gane a cikin hadedde m VS code, e 2) tari ba ya aiki ta atomatik ajiye fayil “.ts” (type Script).

gabatarwar

Just to contextualize, da TypeScript Yana ba ka damar rubuta code ta amfani da karfi da typed tsarin da kuma yi wannan code harhada zuwa tsarki JavaScript. I game da Kayayyakin aikin hurumin Code Yana da wani giciye-dandamali code edita halitta by Microsoft.

// Versions yi amfani da wannan Post:
- Kayayyakin aikin hurumin (VS) code: version 1.14.1
- Typescript: version 2.4.1

Wannan shi ne mai sauki tip, amma za ka iya samun matsaloli idan ba ka san abin da kana yin: na harka :D

Node.js da typescript kafuwa

Daya hanyar shigar ne typescript ta hanyar Node.js kunshin manajan (asl – Kumburi kunshin manajan), don ƙarin yin amfani da-lo, ka farko bukatar shigar Node.js.

Bayan installing da kumburi, bude ko m (umurnin) kuma gudu da wadannan umurni zuwa instalar o TypeScript:

npm kafa -g typescript

Ko da yake Windows Terminal (ko Linux), yin gwajin gudu daga typescript dubawa da shigar version. umurnin “tsk” Yana da wani acronym for typescript tarawa.

tsk -v

matsala

Matsalar ita ce, da umurninSa “tsk” Yana gudana kullum a Windows Terminal, amma ba a hadedde m zuwa a Kayayyakin aikin hurumin Code kanta (VS code), nuna da wadannan kuskure:

'Tut' ba a gane kamar yadda wani na ciki ko na waje umurnin,operable shirin ko tsari fayil.

haka ma, Na ba ya so ya gudu da umurninsa “tsk” domin kowane lokaci ina so in tara fayil “.ts” (tsawo domin typescript). sa'an nan, kamar yadda ko da yaushe yin atomatik tari saving (CTRL + S)? Wannan shi ne abin da za mu gani.

wasu kurakurai

Fuskantar wadannan matsaloli, Posts iske cewa ya yi amfani da compileOnSave, amma wannan ne kawai da goyan bayan Kayayyakin aikin hurumin 2015 com TypeScript> = 1.8.4 e zarra-typescript plugin. a cikin wasu kalmomi, babu kyau amfani compileOnSave babu “tsconfig.json” yi Kayayyakin aikin hurumin Code, da code kasa za su yi aiki:

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

bayani

TSC ba Terminal integrado yi VS Code

Da farko mu magance matsalar tsk ba za a gane a cikin hadedde m na Kayayyakin aikin hurumin Code (VS code).

wasu posts Sun bayar da shawarar sa da hanyar tsk ko npm a cikin hanyar yanayi m, amma mai sauki hanyar warware wannan da aka yi shigarwa na “TypeScript for Kayayyakin aikin hurumin, wanda shi ne m ga VS Code ma.

yanzu a, bayan da kafuwa, bude aiki panel na Kayayyakin aikin hurumin Code, teclando:

// gajerar key ga hadedde m na Kayayyakin aikin hurumin Code:
CTRL+`
// Ko amfani da menu zuwa bude m, a Kayayyakin aikin hurumin Code:
view > Hadakar Terminal

Ka yi kokarin duba version na typescript shiryar da hadedde m VS Code (Ba a Windows Terminal), kuma za a iya yiwuwa aiki:

tsk -v

atomatik tari idan ceton fayil .ts

By da m VS Code ne matsayin da a cikin rubutun directory (.ts), misali:

cd C:\wamp64  www  ts

Ƙirƙiri fayil tsconfig.json ta bugawa a cikin m VS Code:

tsk --init

Ka lura cewa fayil “tsconfig.json” Yana za a halitta a “C:\wamp64 www ts” (yanzu directory).

Open da tsconfig.json da kuma taimaka wa wani zaɓi “sourceMap”: gaskiya, da kuma ajiye canji, da samun da kyau:

  "compilerOptions": {
    /* Basic Zabuka */
    "target": "es5",                          /* Saka ECMAScript manufa version: 'ES3' (tsoho), 'ES5', 'ES2015', "ES2016", 'ES2017', ko 'ESNEXT'. */
    "module": "commonjs",                     /* Saka module code tsara: 'Commonjs', 'AMD', 'Tsarin', 'Umd', 'Es2015', ko 'ESNext'. */
    // "lib": [],                             /* Saka library fayiloli zuwa a kunshe a cikin tari:  */
    // "allowJs": gaskiya,                       /* Kyale javascript fayiloli da za a harhada. */
    // "checkJs": gaskiya,                       /* Rahoton kurakurai a .js fayiloli. */
    // "jsx": "preserve",                     /* Saka JSX code tsara: 'Adana', 'Amsa-yan qasar', ko 'amsa'. */
    // "declaration": gaskiya,                   /* Haifar m '.d.ts' fayil. */
    "sourceMap": gaskiya,                     /* Haifar m '.map' fayil. */
    // "outFile": "./",                       /* Concatenate kuma emit fitarwa zuwa guda fayil. */
    // "outDir": "./",                        /* Onni fitarwa tsarin shugabanci. */
    // "rootDir": "./",                       /* Saka tushen shugabanci na shigar da fayiloli. Yi amfani don sarrafa fitarwar directory tsarin da --outDir. */
    ... ci gaba ...

da ewa ba, Yanzu da ka kawai tafi a cikin m VS Code kuma rubuta umurnin:

tsk -w

Wannan umurnin da aka sa idanu (ko kallon, saboda haka “w” agogon) da aikace-aikace da kuma wani canje-canje a cikin fayiloli .ts, lokacin da zan cece, zai nan da nan tari .JS.

Shi ke nan!

Jumillar adadin hits: 9221

Leave a Reply

Your email address ba za a buga. Bukata filayen suna alama da *