isobject icon indicating copy to clipboard operation
isobject copied to clipboard

Type predicate for easier type checking

Open PumpedSardines opened this issue 4 years ago • 2 comments

PR to address my complaint in issue #27. Instead of the return type being true or false, the function should return if the value is a object or not.

PumpedSardines avatar Oct 17 '21 17:10 PumpedSardines

The point of this function is to return true or false if the value passed in is an object, and it does. I don't understand your issue.

windusayles avatar Apr 21 '22 15:04 windusayles

@windusayles Take this following example if "isObject" returns a bool

const myVariable: unknown = ({ foo: "bar" }) as any;

if(isObject(myVariable)) {
   // TypeScript still sees myVariable as unknown in this scope
}

And this is an example if isObject returns val is { [key: string]: unknown }

const myVariable: unknown = ({ foo: "bar" }) as any;

if(isObject(myVariable)) {
   // TypeScript now sees myVariable as { [key: string]: unknown }
}

PumpedSardines avatar Apr 21 '22 19:04 PumpedSardines