使用通用类和函数

创建泛型类实例:

var stringRunnable = new Runnable<string>();

运行通用功能:

function runSafe<T extends Runnable<U>, U>(runnable: T);

// Specify the generic types:
runSafe<Runnable<string>, string>(stringRunnable);

// Let typescript figure the generic types by himself:
runSafe(stringRunnable);