typescript generator return type code example

Example 1: get function return type typescript

type return_type = ReturnType<() => string>; // string
// or
function hello_world(): string {
  return "hello world";
}
type return_type = ReturnType<typeof hello_world>; // string

Example 2: generator typescript

Generators:
1) They only compute the next value when the user asks for it.(pause the 
    execution after every output) 
2) They can generate infinte values.
3) Calling a generator return in iterable iterator.

//example
function* fibonacci(){
  let a = 0;
  let b = 1;
  while(true){
    yield a ;
    [a, b] = [b, a+b] ;
  }
};
let f = fibonacci();
f().next()   // give 0
f().next()   // give 1