Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type predicate for easier type checking #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Type predicate for easier type checking #28

wants to merge 1 commit into from

Conversation

PumpedSardines
Copy link

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.

@windusayles
Copy link

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.

@PumpedSardines
Copy link
Author

@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 }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants