https://academy.dream-coding.com/courses/typescript
function checkNotNull<T>(arg: T | null): T {
if (arg == null) {
throw new Error('not valid number!');
}
return arg;
}
const number = checkNotNull(123);
interface Either<L, R> {
left: () => L;
right: () => R;
}
class SimpleEither<L, R> implements Either<L, R> {
constructor(private leftValue: L, private rightValue: R) {}
left(): L {
return this.leftValue;
}
right(): R {
return this.rightValue;
}
}
const either: Either<number, number> = new SimpleEither<number, number>(4, 5);
function pay<T extends Employee>(employee: T): T {
employee.pay();
return employee;
}
function getValue(T, K extends keyof T>(obj: T, key: K): T[K] {
return obj[key];
}