3 ms·
I'm having some trouble finding your proposal in the thread... how would you do it?
by otrahuevada 5y ago
I'm having some trouble finding your proposal in the thread... how would you do it?
- jwalton 5y 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.