-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
Make applying DeepReadonly idempotent #107
Make applying DeepReadonly idempotent #107
Conversation
Actually, it turns out that the issue I pointed to above is a real problem, those are two different types according to typescript... Any ideas on how to detect that we've already applied |
99b0ef7
to
ed74ea0
Compare
Maybe this will help (More) Recursive Type Aliases |
Okay, I've pushed up a commit with a new solution that uses a symbol tag to skip applying DeepReadonly again. I'm not sure how you feel about privateish symbol tags, but this is the only way I know how to do something like this. |
@steida I think that'll help with the ultimate definition so we don't have to create separate interfaces to enable recursion, but I'm not sure it helps with this directly, but maybe I'm missing something. |
Unfortunately, the tagging taints Records, which makes things like |
1b9d27e
to
24d4555
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added new comments, please ask if you have any doubts.
Addressed feedback in 9fa8988, I think there may be a conflict between the dts snap and prettier now, however—not sure how you want to resolve that. I could split up the primitive test so prettier doesn't want to reformat. |
Also, let me know if you'd like me to squash the commits or if you just plan on doing it w/ GitHub. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks neat!
|
||
// @dts-jest:pass:snap -> _DeepReadonlyObject<{ first: { second: { name: string; }; }; }> | ||
testType<DeepReadonly<DeepReadonly<NestedProps>>>(); | ||
// @dts-jest:pass:snap -> _DeepReadonlyObject<{ first: { second: { name: string; }[]; }; }> | ||
testType<DeepReadonly<DeepReadonly<NestedArrayProps>>>(); | ||
|
||
// @dts-jest:pass:snap -> string | number | bigint | boolean | symbol | null | undefined | ||
testType< | ||
DeepReadonly<string | null | undefined | boolean | number | bigint | symbol> | ||
>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍
: T extends _DeepReadonlyArray<infer U> | ||
? _DeepReadonlyArray<U> | ||
: T extends _DeepReadonlyObject<infer V> | ||
? _DeepReadonlyObject<V> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
fixes #106
This isn't as clean as I'd like—ideally a recursive application would have no impact. For example, the newly added test would match as if it weren't applied twice:
Above, the
_DeepReadonlyObject
is superfluous and isn't there if applied only once.Description
Related issues:
Checklist
For bugfixes:
For new features:
dts-jest