Posts

Showing posts from July, 2018

TypeScript and APEX

Image
TypeScript is a typed superset of JavaScript. That is, you can use the familiar JavaScript syntax you are used to, but where it gets enhanced is the fact it is can be strongly typed to give you compile time warnings. The most example is the sum of two numbers. A typical JavaScript function would looks like: function add(num1, num2){ return num1 + num2; } By looking at this code, by the function name and the return statement, we can see that the idea would be to add two numbers together. In JavaScript, depending what the user passed in, it could do string concatenation, implicit type casting. So if you do: add(1,2) This will return 3 If you do: add ("1", 2) This will return 12 (string concatenation). Since we want this function to always add two numbers, using TypeScript, we can change the definition to be: function add(num1: number, num2: number): number { return num1 + num2; } Now the TypeScript engine is always going to expect the inputs to