typescript kohinga whakaora aunoa i Visual Waehere Studio

I roto i tenei pou ka whakaoti tatou e rua raruraru: 1) whakahau “tsk” e kore e mohio te reira i roto i te integrated tauranga VU waehere, e 2) e kore e haaputuraa mahi aunoa ina tiaki kōnae “.TS” (Patohia Hōtuhi).

whakataki

Just ki contextualize, te typescript āhei te reira ki a koutou te tuhituhi waehere te whakamahi i te hanganga kaha pato, ka kua tenei waehere haaputuhia ki JavaScript parakore. kua Visual Waehere Studio Ko te ētita waehere ripeka-atamira i hanga e Microsoft.

// Putanga whakamahia i roto i tenei Post:
- Visual Studio (VU) Code: putanga 1.14.1
- typescript: putanga 2.4.1

Ko te matamata ngāwari tenei, engari kia whai koe raruraru, ki te kahore koutou e mohio ki ta e mahi koe: toku take :D

Node.js me tāuta typescript

Ko tētahi ara ki te tāuta he typescript roto kaiwhakahaere mōkihi Node.js (ASL – kaiwhakahaere mōkihi Kōpuku), hoki atu te whakamahi i-na, koe hiahia tuatahi tāuta Node.js.

I muri i te tāuta i te Kōpuku, tuwhera kāpeka ranei (whakahau) ka rere i te whakahau e whai ake nei ki Typescript o Tāuta:

npm tāuta -g typescript

Ahakoa te Kāpeka Windows (tou Linux), hanga i te oma whakamātautau o te typescript arowhai i te putanga tāuta. Ko te whakahau “tsk” Ko te acronym mo Compiler typescript.

tsk -v

raruraru

Ko te raruraru ko e te whakahau “tsk” ngāue te reira i te tikanga i roto i Windows Kāpeka, otiia e kore e roto i te kāpeka integrated haere mai i roto i Visual Studio Waehere iho (waehere VU), whakaatu i te hapa e whai ake nei:

'Parakipere' e kore te mohio rite he whakahau ā-waho ranei,hōtaka operable puranga ranei kōnae.

ano, e kore ahau i hiahia ki te whakahaere i te whakahau “tsk” hoki te wā katoa hiahia ahau ki te whakahiato i tētahi kōnae “.TS” (toronga mō te typescript). ka, hanga rite tonu whakaora kohinga aunoa (CTRL + S)? Ko tenei he aha ta tatou e kite.

atu hapa

Pūtake enei raruraru, Whakairinga kitea e ahau e mea ana ki te whakamahi i compileOnSave, engari kei te anake tautoko tenei e Visual Studio 2015 com typescript> = 1.8.4 e mono ngota-typescript. i roto i te mau parau te tahi atu, kahore whakamahi pai compileOnSave kahore “tsconfig.json” mahi Visual Waehere Studio, te waehere i raro kore e mahi:

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

otinga

TSC i roto i te integrated Terminal VU Code

Tuatahi whakaoti tatou te raruraru o tsk e kore e mohio i roto i te tauranga integrated o te Visual Waehere Studio (waehere VU).

etahi Whakairinga faaite ratou e maka ana i te ara o te tsk npm ranei i roto i te tāupe taiao E'A, engari he ara ngāwari ki te whakaoti i tenei i te mahi tāutanga o “Typescript mō Visual Studio, i te mea hototahi hoki VU Code hoki.

inaianei ae, i muri i te tāutanga, whakatuwhera i te rōpū mahi o te Visual Waehere Studio, patopato:

// kī pokatata mo te tauranga integrated o te Visual Waehere Studio:
CTRL+`
// te whakamahi ranei i te tahua ki te whakatuwhera i te kāpeka i roto i Visual Waehere Studio:
Tirohia > integrated Kāpeka

Whakamātauria ki tirohia te putanga o te typescript whakatika i te kāpeka ngātahi VU Code (Ehara i roto i Windows Kāpeka), a ka pea e mahi:

tsk -v

haaputuputuraa aunoa ina tiaki i te kōnae .TS

E te kāpeka VU Code he tūranga i roto i to koutou whaiaronga hōtuhi (.TS), hei tauira:

kōpae C:\wamp64  www  ts

Waihanga i te kōnae tsconfig.json mā te pato i roto i te tauranga Waehere VU:

tsk --init

Kia mōhio e te kōnae “tsconfig.json” Ka hanga te reira i roto i “C:\wamp64 www ts” (whaiaronga nāianei).

Whakatūwhera te tsconfig.json ka taea te kōwhiringa “sourceMap”: pono, ka whakaora i te huringa, whiwhi pai:

  "compilerOptions": {
    /* Kōwhiringa Basic */
    "target": "es5",                          /* Tauwhāiti ECMAScript putanga ūnga: 'ES3' (taunoa), 'ES5', 'ES2015', 'ES2016', 'ES2017', ranei 'ESNEXT'. */
    "module": "commonjs",                     /* Tauwhāiti waehere kōwae whakatupuranga: 'Commonjs', 'AMD', 'Pūnaha', 'Umd', 'Es2015', ranei 'ESNext'. */
    // "lib": [],                             /* Tauwhāiti kōnae whare pukapuka ki te kia whakaurua i roto i te haaputuraa:  */
    // "allowJs": pono,                       /* Tukua javascript kōnae ki te kia haaputuhia. */
    // "checkJs": pono,                       /* hapa Report i roto i ngā kōnae .JS. */
    // "jsx": "preserve",                     /* Tauwhāiti waehere JSX whakatupuranga: 'Tiaki', 'Tauhohe-Māori', ranei 'tauhohe'. */
    // "declaration": pono,                   /* Mahia hāngai kōnae '.d.ts'. */
    "sourceMap": pono,                     /* Mahia kōnae hāngai '.map'. */
    // "outFile": "./",                       /* CONCATENATE ka emit putanga ki te kōnae kotahi. */
    // "outDir": "./",                        /* Anga hanganga putanga ki te whaiaronga. */
    // "rootDir": "./",                       /* Tauwhāiti te whaiaronga pakiaka o ngā kōnae tāuru. Whakamahia ki te whakahaere i te hanganga whaiaronga putanga ki --outDir. */
    ... tonu ...

hohoro, Na haere noa koe i roto i te tauranga VU Code ka pato i te whakahau:

tsk -w

Tenei whakahau Ko aroturuki (e matakitaki ana ranei, reira “w” de mataaratanga) te tono me tetahi huringa i roto i ngā kōnae .TS, ka ora, e te haaputuputuraa tonu .js.

Ko te reira!

maha Tapeke o täia: 10612

Waiho i te Reply

Ka kore e whakaputaina tō wāhitau īmēra. Kua tohua ngā āpure e hiahiatia ana ki *