Skip to content

Remove If* types in favour of a single If type#1135

Merged
sindresorhus merged 11 commits intomainfrom
refactor/remove-all-if-types
May 12, 2025
Merged

Remove If* types in favour of a single If type#1135
sindresorhus merged 11 commits intomainfrom
refactor/remove-all-if-types

Conversation

@som-sm
Copy link
Copy Markdown
Collaborator

@som-sm som-sm commented May 12, 2025

Completes point no. 16 of #450.

Removes all If* types (IfAny, IfNever, IfUnknown, IfNull & IfEmptyObject) in favour of a single If type as suggested here.

NOTE:

  • I have kept the IfNotAnyOrNever type because I feel it's still a nice abstraction as it handles two checks, and the defaults of any and never are mostly useful.

@som-sm som-sm marked this pull request as ready for review May 12, 2025 11:16
@som-sm som-sm requested a review from sindresorhus May 12, 2025 11:16
@som-sm som-sm force-pushed the refactor/remove-all-if-types branch from 3ddc1ab to 56fa97a Compare May 12, 2025 11:19
@sindresorhus
Copy link
Copy Markdown
Owner

I have kept the IfNotAnyOrNever type because I feel it's still a nice abstraction as it handles two checks, and the defaults of any and never are mostly useful.

👍

@sindresorhus
Copy link
Copy Markdown
Owner

sindresorhus commented May 12, 2025

I think it would be nice to just keep alias to the existing If* types using the If type with a deprecated doc comment, in index.d.ts. That would make it easier for people to migrate.

type IfAny<T, ...> = If<IsAny<T>, ...>;

@sindresorhus
Copy link
Copy Markdown
Owner

The deprecated comment could say it will be removed in the next major version.

@som-sm
Copy link
Copy Markdown
Collaborator Author

som-sm commented May 12, 2025

I think it would be nice to just keep alias to the existing If* types using the If type with a deprecated doc comment, in index.d.ts. That would make it easier for people to migrate.

Yeah, I too thought so, will update the PR.

@som-sm som-sm force-pushed the refactor/remove-all-if-types branch from e618d23 to 336c260 Compare May 12, 2025 17:37
Comment on lines +6 to 8
@deprecated This type will be removed in the next major version. Use the {@link If} type instead.
@see {@link IsAny}
Copy link
Copy Markdown
Collaborator Author

@som-sm som-sm May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: The {@link If} link is still not clickable, because If is not imported in this file.

And this happens at many places (like the @see {@link IsAny} link), I'll look into this separately.

@som-sm
Copy link
Copy Markdown
Collaborator Author

som-sm commented May 12, 2025

Updated the PR to just deprecate the If* types.

Properly gets flagged while importing these types:
image

@sindresorhus sindresorhus merged commit 4c2151a into main May 12, 2025
6 checks passed
@sindresorhus sindresorhus deleted the refactor/remove-all-if-types branch May 12, 2025 18:05
This was referenced May 12, 2025
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