Hacker News new | ask | show | jobs
by otrahuevada 1709 days ago
I'm having some trouble finding your proposal in the thread... how would you do it?
1 comments

:) 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.