-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add an overload to Object.freeze that preserves literal types #33767
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
Add an overload to Object.freeze that preserves literal types #33767
Conversation
@typescript-bot test this |
Heya @weswigham, I've started to run the extended test suite on this PR at a5cb1a6. You can monitor the build here. It should now contribute to this PR's status checks. |
@typescript-bot user test this |
Heya @weswigham, I've started to run the parallelized community code test suite on this PR at a5cb1a6. You can monitor the build here. It should now contribute to this PR's status checks. |
The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master. |
@typescript-bot user test this inline |
Heya @sandersn, I've started to run the diff-based community code test suite on this PR at 89cfe35. You can monitor the build here. Update: The results are in! |
@sandersn |
@weswigham this seems like a plausible change even though it's old. It didn't create any new errors in the user tests. Think it's worth trying out? |
Yeah, I think it's still a reasonable change. |
Out of curiosity... if I hover over the call using this signature I might see something like this: function freeze<{
a: 1;
}, string | number | bigint | symbol>(o: {
a: 1;
}): Readonly<{
a: 1;
}> In here, the |
We assign positions literal types when they're contextually typed by a generic with literal bases in the constraint. |
This way when you write something like
(snippet from webpack) you get something with literally-typed members as a result, if possible. The intuition seems to be that it should just work like that already, but it does not currently.