Modern Full-Stack Development


A Quick Detour: Custom-Type Definitions



Download 5,64 Mb.
Pdf ko'rish
bet75/107
Sana06.08.2021
Hajmi5,64 Mb.
#140576
1   ...   71   72   73   74   75   76   77   78   ...   107
Bog'liq
Modern Full-Stack Development Using TypeScript, React, Node

 A Quick Detour: Custom-Type Definitions
Any time you see a d.ts file – and you’ll see them frequently with TypeScript – it means 
that the developer has provided TypeScript some additional type information about an 
API written in JavaScript. This allows TypeScript to do its thing, ensuring that types are 
correctly used and everything else it provides. This contrasts with the other alternative: 
rewriting the API in TypeScript. Imagine if you want to use jQuery, but there isn’t a 
TypeScript version available. As long as you have a declaration file for it, you can still use 
it in TypeScript, complete with all the checking (and IntelliSense inside an IDE) that it 
provides.
Note  frequently, you’ll see index.d.ts instead of d.ts. anything 
*
.d.ts is 
a typeScript declaration file, the name is more convention than anything else, so 
some variation is normal.
This all comes into play with the image imports. If you don’t have this d.ts file, 
you’ll find that tsc flags each of those imports as an error saying that the module can’t 
be found. You can technically still get them to import using require() notation, but it’s 
something of an eyesore to use import everywhere but require() just for the images, so 
better to make it work the ideal way I figure. The way to solve this is to declare a module 
for TypeScript, which is what we find in the d.ts file:
declare module "*.png" {
 const value: any;
 export = value;
}
Now, TypeScript will know that the image files, any module name ending in .png in 
fact, are a valid module. The code will compile, and everything will work as expected.
Chapter 11   time for fun: BattleJong, the Client


321
Remember definitelytyped.org? If you go there and pull up a random module in 
the search engine, when you get to the NPM page for the module, you should see a link 
somewhere to where the files were exported from. Click that link, and you should see 
some sort of *.d.ts file in the list of files. Doing that, you can view the type information 
provided for any JavaScript module you want to use.

Download 5,64 Mb.

Do'stlaringiz bilan baham:
1   ...   71   72   73   74   75   76   77   78   ...   107




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish