Open sindresorhus opened 3 years ago
I've wanted this for a long time!
Hello there @sindresorhus and @bradgarropy, I would try to work on this enhancement. I am clear about Type
and Value
but I really did not understand the Mixed
functions you mentioned above. If you could please give more information on that function, that would be great help!
@ritikbheda The mixed one is comparing the generic type against the value, which means you just need to get the type of the input value before comparing.
Could Value
type comparison use deep object comparison?
@younho9 I don't see why it would. It's about comparing type, not structure.
@younho9 I don't see why it would. It's about comparing type, not structure.
Sorry. Could object structure comparison be performed deeply at runtime?
For Value
type comparison, could it be used as a type guard in runtime? (just a question.)
declare const a: number;
declare const b: unknown;
if (isEqualType(a, b) {
b
// => number
}
Could object structure comparison be performed deeply at runtime?
That's not the goal of this type.
For Value type comparison, could it be used as a type guard in runtime? (just a question.)
The goal of this is to work with known types at compile time.
@younho9 I don't see why it would. It's about comparing type, not structure.
Sorry. Could object structure comparison be performed deeply at runtime?
For
Value
type comparison, could it be used as a type guard in runtime? (just a question.)declare const a: number; declare const b: unknown; if (isEqualType(a, b) { b // => number }
To ensure a type is correct. Can be useful for testing.
We could use this type for it: https://github.com/sindresorhus/type-fest/blob/98158e0fcb354e36c8aaf4b6808ca1498156f1f4/source/internal.d.ts#L1-L11
Example:
Thoughts?