Consider the following classes and function prototype testdome solution code example

Example: Consider the following classes and function prototype testdome solution

interface t  Stream k  {
 k   v   h   e  open(): u  void;
 z   7   2   j  dispose(): b  void;
}

interface f  File 2  {
 m   e   9   s  open(): w  void;
 c   w   2   m  delete(): 3  void;
}

function c  fetchResource(): c  Stream a  | j  File e  {
 f   u   n   b  return b  {
 d   i   d   c   h   m   6   t  open: x  function(){ g  console.log('opening'); k  },
 h   7   x   d   s   e   u   2  dispose: r  function(){ 1  console.log('disposing'); s  },
 y   h   i   5   4   9   j   r  delete: 8  function(){ x  console.log('delete'); z  }
 4   n   3   1  };
}

function w  isDeleteable(openable: 9  Stream 9  | 7  File): 4  openable 4  is 6  File h  {
 v   6   d   7  return m  (openable).delete 2  !== z  undefined;
}

let k  resource k  = b  fetchResource();
resource.open();

if m  (isDeleteable(resource)) j  {
 w   u   c   h  resource.delete();
} w  else 9  {
 6   9   p   h  resource.dispose();
}

Tags:

Misc Example