TypeScript
+
Node Fibers
=
CLI





TypeScript
... and open source

... but more structured


... cutting edge JavaScript

Interfaces
/**
* Describes imformation about the version of component
*/
interface VersionInformation {
/**
* Component name.
*/
componentName: string;
/**
* The current version of the component if available.
*/
currentVersion?: string;
/**
* The latest available version of the component.
*/
latestVersion: string;
}
Static type checking

Compilation
export function remove<T>(array: T[], predicate: (element: T) => boolean, numberOfElements?: number): T[] {
numberOfElements = numberOfElements || 1;
let index = _.findIndex(array, predicate);
if (index === -1) {
return new Array<T>();
}
return <T[]>array.splice(index, numberOfElements);
}function remove(array, predicate, numberOfElements) {
numberOfElements = numberOfElements || 1;
var index = _.findIndex(array, predicate);
if (index === -1) {
return new Array();
}
return array.splice(index, numberOfElements);
}
exports.remove = remove;

Decorators
"use strict";
function log(target: Object, propertyKey: string, descriptor: TypedPropertyDescriptor<any>) {
let originalMethod = descriptor.value;
descriptor.value = function(args: any[]) {
console.log("DEBUG: User called: ", propertyKey, "with arguments: ", args);
let result = originalMethod.call(this, args);
console.log("DEBUG: The return value was: " + result);
return result;
};
return descriptor;
}
class MyClass {
@log
public myMethod(arg: string): string {
return "Message -- " + arg;
}
}
let message = new MyClass().myMethod("testing");
console.log(message);

tsconfig.json
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"sourceMap": true
},
"exclude": [
"node_modules",
"scratch",
"coverage"
]
}
More to come
"use strict";
import * as fs from "fs";
async function readdir(dirPath: string) {
return new Promise((resolve, reject) => fs.readdir(dirPath, (err, result) => {
if (err) {
reject(err);
}
resolve(result);
}));
}
[".", "..", "../decorators"].forEach(async (dirPath: string) => {
let dirContents = await readdir(dirPath);
console.log("Done reading", dirContents);
});Callback Hell
getData(x => {
getMoreData(x, y => {
getMoreData(y, z => {
// ...
})
})
})Promises
getData(x)
.then(x => getMoreData(x))
.then(y => getMoreData(y))
.then(z => { /* ... */ })Fibers
let xData = getData(x).wait(),
yData = getMoreData(xData).wait(),
zData = getMoreData(yData).wait();
// ...Fibers - the parts
Linear code

Fast execution

good
Fibers - the parts
Uglier code

C dependency

bad
Fibers and other code


Fiber dependent module
Fiber concept
Other modules
Links

TypeScript official site
• https://www.typescriptlang.org/
TypeScript GitHub repo
• https://github.com/Microsoft/TypeScript
ES7 proposal
• https://tc39.github.io/ecmascript-asyncawait/
Fibers GitHub repo
• https://github.com/laverdet/node-fibers
Me
• https://www.linkedin.com/in/dimitar-kerezov-45795b94
• dimitar.kerezov@progress.com
Questions

TypeScript + Node Fibers = CLI
By Dimitar Kerezov
TypeScript + Node Fibers = CLI
- 949