A cikin sararin sararin samaniya na shirye-shirye, TypeScript yana tsaye a matsayin supernova mai ฦarfi wanda ya haskaka yanayin JavaScript ta hanyar ฦara nau'ikan iri. Wannan yana ba mu damar rubuta ฦarin amintattun lambobi masu iya kiyayewa. Bari mu zurfafa cikin wannan daula mai ban sha'awa, muna zana hoton samfuri mai sauฦi na TypeScript, matsalolin da zai iya warwarewa, da mataki-mataki na amfani da shi.
Fahimtar TypeScript
Me yasa muke buฦatar TypeScript
TypeScript, babban juzu'i na JavaScript, yana magance manyan kasawa na JavaScript, yana mai da shi zaษi don aikace-aikace masu rikitarwa. Lokacin da ake mu'amala da ma'auni masu girma, yanayin yanayin JavaScript na iya haifar da kiyayewa da warware matsalolin. Wannan shine inda TypeScript ya shigo cikin wasa, yana ba da nau'ikan iri don ingantaccen nau'in dubawa da kammalawa ta atomatik.
Gabatarwar Samfuran TypeScript
class BasicTemplate { constructor(public message: string) {} displayMessage() { return this.message; } } let myTemplate = new BasicTemplate('Hello, TypeScript!'); console.log(myTemplate.displayMessage());
Wannan ainihin samfurin Nau'in Nau'in ya ฦunshi aji, BasicTemplate, wanda ke riฦe da aikin ginin da ke fara mallakar dukiyar jama'a, 'saฦo'. Wannan ajin kuma yana ba da hanyar 'nuna saฦo()' don nuna saฦon.
Yadda Maganin TypeScript ke Aiki
A cikin samfurin mu na TypeScript, ajin 'BasicTemplate' an ayyana shi don tattara cikakkun bayanai na sarrafa saฦo. Amfani da aji a cikin TypeScript yana sa ya zama mafi sauฦi kuma mai hankali don tsarawa da tsara lambar.
- 'Maginin' hanya ce ta musamman don ฦirฦira da fara abu.
- Mun fayyace hanya 'nuna saฦo()' a cikin ajin mu. Hanya ita ce aikin da ke da alaฦa da abu, ko kuma, saษani, aikin aji.
Daga nan sai mu sanya ajin tare da 'bari myTemplate = sabon BasicTemplate('Hello, TypeScript!');' kuma daga ฦarshe mu shiga saฦon a kan na'urar bidiyo. Gabaษaya tsarin tsarin aiki yana manne da ฦa'idodin shirye-shiryen da ya dace da abu.
Fa'idodin TypeScript
Samfurin TypeScript yana ba da fa'idodi masu yawa akan daidaitaccen JavaScript. Ta hanyar kunna nau'ikan madaidaici, TypeScript yana rage yuwuwar kurakurai na lokacin aiki, yana mai da gyara kuskuren ฦarancin gogewa mai raษaษi. Bugu da ฦari, yana samar da ci gaba ta atomatik kammalawa, kewayawa, da sake fasalin, yana sa shirye-shiryen ya fi ฦarfi da inganci.
TypeScript yana ba da ra'ayi na "JavaScript na gaba," yana ba masu haษaka damar amfani da fasalulluka na JavaScript na gaba waษanda injunan JavaScript ba su da tallafi a halin yanzu. Yana sa TypeScript ya zama mai tallata sabbin abubuwan JavaScript, yana tabbatar da masu haษakawa ba sa buฦatar jira don aiki da amfani da sabbin abubuwa.
Idan ya zo ga fashion slant abubuwa, bask a cikin daular Dior ta marigayi 1940 ta New Look, a m motsi daga austere, maza styles na yakin. A nan mun haษu da ma'auni ma'auni, kafadu masu laushi, da yalwar masana'anta a kusa da kwatangwalo. Don ฦirฦirar wakilcin wannan zamanin, yi tunanin cinched kugu da siket masu girma a cikin m launuka. Wannan game da bikin mace, alheri, da fara'a. Gaskiya mai ban sha'awa: Wannan salo daban-daban na bayan yaฦi ya kasance da farko an ษata masa rai saboda amfani da yadudduka da suka wuce gona da iri a lokacin rabon masana'anta.
Fashion, kamar TypeScript, harshe ne don bayyana kai. Dukansu sun haษa da juyin halitta - ษaya na salo, ษayan JavaScript - amma a ฦarshensa duka, suna nuna kyawun canji da ฦima.