Skip to content

Drop typed MIME-type and extension enumeration #693

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

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

Borewit
Copy link
Collaborator

@Borewit Borewit commented Nov 23, 2024

This PR introduces a change where the MIME type (mime) and extension (ext) are no longer constrained by fixed enumerated TypeScript typings. Instead, these values are now represented as strings. This change has the following implications:

Drops Fixed Enumerated Typings:
Previously, the library’s TypeScript typings enforced that mime and ext could only be one of a predefined set of values. This change removes that strict enumeration, allowing greater flexibility, especially when custom detectors are involved.

Supports Custom Detectors:
The flexibility aligns with the implementation introduced in #603, where custom detectors were added. Custom detectors can return MIME types and extensions beyond the predefined list, and enforcing enumerated typings would have conflicted with this capability.

Resolves Issue #692:
This change addresses the concerns raised in #692, where the library’s core functionality and custom detector extensibility were at odds with the strict TypeScript typings. By treating mime and ext as strings, the library now accommodates both core-supported and custom-detected types without imposing unnecessary constraints.

Benefits:
Extensibility: Users can define custom detectors that return unique MIME types and extensions, even if these are not officially recognized by the core library.
Type Safety Tradeoff: While dropping fixed enumerated typings slightly reduces the strictness of TypeScript’s type safety, it ensures the library remains flexible and compatible with its extensibility features.
This approach maintains a balance between usability and flexibility, ensuring file-type can cater to diverse use cases without breaking custom implementations.

@Borewit Borewit added the improvement Improvement of existing functionality label Nov 23, 2024
@Borewit Borewit self-assigned this Nov 23, 2024
@Borewit Borewit linked an issue Nov 23, 2024 that may be closed by this pull request
2 tasks
@Borewit Borewit requested a review from sindresorhus November 23, 2024 11:34
@sindresorhus
Copy link
Owner

I agree

@sindresorhus
Copy link
Owner

You need to update https://github.com/sindresorhus/file-type/blob/main/.github/pull_request_template.md too

With the introduction of custom detectors the possible return file type is no longer in the list of directly support file types (both extension and MIME-type).
@Borewit Borewit force-pushed the drop-typed-file-type-enumerations branch from fda7dde to a19a79e Compare November 25, 2024 20:09
@sindresorhus sindresorhus merged commit 0ff11c6 into main Nov 26, 2024
6 checks passed
@sindresorhus sindresorhus deleted the drop-typed-file-type-enumerations branch November 26, 2024 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allowed return type for custom detectors are to narrow
2 participants