What is typings? I see it in Angular 2 + TypeScript code. What are its usage?
types are information about the structure in memory.... for example in C : a variable of the type integer allocates 4 bytes (ignoring the endians¹), so the compiler knows the bit chain 00000000 00000000 00000000 00000001 is 1 and not ' a ' (assuming the pointer points to the last byte²).
types can be used in branch predictions, for example you got 12 time a function that returns int a + int b. some modern compiler will inline the instructions for that so instead if 12 times a + b there is only 1 a + b. (as jump point for instructions in the memory)
types can be used to spot programmatic issues if you pass the wrong type into a function.
or for interface / type inferences.
basically types are a control structure that allows predictions about memory, process-flow, execution-model. The way they are applied/used varies based on the implementation of the compiler / interpreter.
I'm sure I forgot a lot of things.
typescript is a transpiler that will compile ts code into different JS (es5, es6, es2005) versions. the idea is to specify the interfaces and having a clear idea what's happening. basically eliminating the problem of "not knowing" what comes in and what goes out
hope that helped. or do you just mean Types in typescript ?
¹ endians the order bytes are read - left to right, right to left.
² ignoring the fact that the type char usually is only 1 byte long, hence it's more important where the pointer in memory points than the theoretical bit length of the integer, it could be seen as 4 characters not 1 as well I assumed a 32 bit architecture hence the integer is 4x8 bit
TypeScript is strongly typed language where is JS is not. Hence any object/var that we declare has to be of some specific data type. When we define classes in TypeScript we by default tend to define data types. But you want to build some library using javascript but should be able to use with TypeScript we need definition file that includes type definitions for all the variables. Now why we need this ? We already have many libraries like JQuery, HighCharts etc that are build with JavaScript. And when we include this in our project cannot get recognized by the TypeScript compiler. We need to enable compiler to be able to recognize what these libraries are and we create definition file known as TSD. It contains type informations about the JavaScript library and enables the TypeScript developer to use the library objects like they where TypeScript objects. We can either write them or use the existing ones using TSD manager. You can get more information here on how to write it : basarat.gitbooks.io/typescript/content/docs/types…
Sébastien De Saint Florent
typings is to type definitions (.tsd files) what npm is to javascript packages