-
Notifications
You must be signed in to change notification settings - Fork 0
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
readonly
and mutable types are incorrectly considered equal
#3
Comments
This one is going to be challenging because to my knowledge If I tried to infer readonly keys from a mixed object type for example, I would get all the keys regardless of whether they are readonly or not. I'm keeping this issue open for now, because I could be wrong, but I am not sure I can do something about it. |
this method seems to work: export type Equals<X, Y> =
(<T>() => T extends X ? 1 : 2) extends
(<T>() => T extends Y ? 1 : 2) ? true : false;
type A = Equals<{readonly a: number},{a: number}> // false
type B = Equals<{readonly a: number},{readonly a: number}> // true though that has its own drawbacks, many of which are mentioned in microsoft/TypeScript#27024 |
Very nice. I leveraged this implementation to infer readonly keys and to add them as an additional prop to the object. The change only affects |
I haven't distilled this to a minimal reproduction yet, but I think this may have had some unintended consequences. I have two object types which don't use the readonly keyword but they aren't considered equal even though if you compare each key in the objects individually they all are considered equal. |
Ok, so that was easier than I expected... This used to pass, but now fails on the latest version of import { test } from "ts-spec";
type Foo = { helloWorld: string };
interface Bar {
helloWorld: string;
}
test("Foo == Bar" as const, (t) => t.equal<Foo, Bar>()); |
Thanks for the quick feedback. It should now work as expected. |
By the way, |
playground
The text was updated successfully, but these errors were encountered: