Allowed return type for custom detectors are to narrow
Closed this issue · 3 comments
Description
I have implemented a custom detector that also works without any problems.
However, the typescript types seem to be a bit too restrictive for the return value. Custom detectors must return a FileTypeResult (which limits them to already existing extensions/mine-types).
Am I mistaken, or shouldn't the FileTypeResult type actually be extendable somehow?
Existing Issue Check
- I have searched the existing issues and could not find any related to my problem.
File-Type Scope Acknowledgment
- I understand that file-type detects binary file types and not text or other formats.
I agree with your point. Furthermore, this issue extends beyond the types returned by custom detectors (as specified in the TypeScript typings). Since the core file-type library allows the addition of custom detectors, there’s no guarantee that the returned MIME types will align with the ones officially enumerated in the library’s typings. This introduces potential inconsistencies that developers need to handle when using custom detection logic.
Please excuse the delay in replying, I have only just seen that there is a PR on this topic.
Shouldn't it theoretically be possible to infer the exact types via the return types of the customDetectors that are passed to the constructor? Am I missing something?
It may be possible, but the exact types are not that useful anyway, so no point in making it so complicated.