Closed djak250 closed 9 months ago
The typing of Tags
is only best-effort, and this is actually behaving as expected--if you're setting numeric values or any other advanced settings, I'd expect you to wrap ExifTool.read
in some service layer, and Pick
the Tag
interface to taste.
If you've got a good idea for adding dynamic typing to Tag
based on options inference (which would require the ExifTool class to pull in a generic type that then mutates .read
's return value), know that I'm happy to review pull requests. Full disclosure, though: I'm a bit hesitant to add labyrinthine TypeScript signatures, as they can be a bit brittle on major TypeScript version upgrades.
I don't know if it is possible to have the type update based on the dynamic properties of the ReadTaskInputs
. But my main request is to remove the extends requirement for read<T extends Tags = Tags>
to instead be read<T = Tags>
. I understand it gives the end developer the opportunity to mistype things to not be a close match to the Tags
interface, but if they're overriding the default generic, I think it's safe to say they're being intentional about the override.
Describe the bug
exifTool.read<T>
requires T to extend Tags. However, passing innumericTags
on theReadTaskOptions
potentially modifies the expected value. For instance,FocalLength
has a type ofstring
inTags
, but when passed intonumericTags
, the actual value is anumber
. When trying to override the generic to allow this type to be reflected in the type checking, the compiler complains, since settingFocalLength
tonumber
(it's actual type) breaks the extension ofTags
, which is required by the type signature ofexifTool.read
.To Reproduce
Expected behavior
const tags
to be of typeTagsWithNumericFocalLength
Actual behavior
due to overly strict type enforcement.