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

SetOptional/SetRequired/SetReadonly: Fix when the second argument is any #1007

Conversation

som-sm
Copy link
Contributor

@som-sm som-sm commented Dec 15, 2024

Currently, when the second argument to Set-Optional is any, it returns an index signature. And this because Set-Optional uses Pick.

type T = SetOptional<{a: 1; b: 2}, any>; // => type T = {[x: string]: any}

This PR modifies this behaviour to instead return all keys marked as optional.

type T = SetOptional<{a: 1; b: 2}, any>; // => type T = {a?: 1; b?: 2}

Similar changes made for Set-Required & Set-Readonly.


Additionally, also fixes Set-Optional when instantiated with unions.

@som-sm som-sm changed the title Set-Optional/Set-Required/Set-Readonly: Fix when the second argument is any` Set-Optional/Set-Required/Set-Readonly: Fix when the second argument is any Dec 15, 2024
@sindresorhus sindresorhus changed the title Set-Optional/Set-Required/Set-Readonly: Fix when the second argument is any SetOptional/SetRequired/SetReadonly: Fix when the second argument is any Dec 16, 2024
@sindresorhus sindresorhus merged commit fdbcb11 into sindresorhus:main Dec 16, 2024
11 checks passed
@sindresorhus
Copy link
Owner

@som-sm Thanks for all the recent good contributions 🙏

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

Successfully merging this pull request may close these issues.

2 participants