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

Proposal: is.equalType() #145

Closed
younho9 opened this issue Dec 8, 2021 · 2 comments
Closed

Proposal: is.equalType() #145

younho9 opened this issue Dec 8, 2021 · 2 comments

Comments

@younho9
Copy link

younho9 commented Dec 8, 2021

It would be useful as a type guard function of inferring the type of another variable compared to the type of one variable.

is.equal = <A>(a: A, b: unknown): b is A => is(a) === is(b);

/**
const b: unknown = 'unknown value';

if(is.equal('hello', b)) {
	b // b is string.
}
*/

It would be not strict type level equal.

Related: sindresorhus/ts-extras#2

@sindresorhus
Copy link
Owner

I'm not sure this is a good idea. It would work fine for simple things, but for most custom objects, the type would just be Object, which means it would be true even when the objects differ.

@sindresorhus sindresorhus changed the title Proposal: is.equal() or is.equalType() Proposal: is.equalType() Jan 1, 2022
@younho9
Copy link
Author

younho9 commented Jan 3, 2022

Your point is right... To correctly infer the object type, a deep identity comparison is required, but I think it's too expensive for type inference.

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

No branches or pull requests

2 participants