Hacker News new | ask | show | jobs
by jwalton 1709 days ago
:) Fair enough:

    function isHuman(obj: unknown): obj is Human {
      return !!obj && 
        typeof obj === 'object' &&
        typeof (obj as any).name === 'string' &&
        typeof (obj as any).age === 'number';
    }
This checks the shape of the object, and returns true if it's a `Human`. This will work for array or objects or classes or anything.