Drop typed MIME-type and extension enumeration #693
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.