-
-
Notifications
You must be signed in to change notification settings - Fork 95
Add XMP raw string type to ExpandedTags["xmp"] type #197
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
Thanks! Will merge at the same time as the other one. |
Or actually, this can't make anyone's code start failing during type checking, right? It just expands what is correct. |
It probably won't fail the type checking. However, I found a problem with the combination of intersection types and index signature. So far the assignment to ExifReader.load(file, { expanded: true }).then((tags) => {
if(tags.xmp) {
tags.xmp._raw= ''
tags.xmp['Foo'] = {
value: '',
attributes: {},
description: ''
}
tags.xmp['Bar'] = '' // Type 'string' is not assignable to type 'XmpTag'
}
}); following code has the same problem. ExifReader.load(file, { expanded: false }).then((tags) => {
tags['Foo'] = {
description: '',
value: 1
}
});
// throw an error
// Type 'number' is not assignable to type 'string & XmpTag[] & XmpTags & String'.
// Type 'number' is not assignable to type 'string'. |
Not sure I understand what the problem is. Both of the examples should fail type checking as I see it, and that should be the case even before your change in this PR. |
I've confirmed that the first example can't assign a string other than As you pointed out, the second exmaple is failing type checking before this PR. |
This change effectively makes it impossible to create tests/mocks based on XMP tags. After upgrading from 4.5.0, the following code will not compile due to missing mockExifLoad.mockResolvedValueOnce({
xmp: {
description: { attributes: {}, description: "My description", value: null as never },
},
}); However, adding I understand the idea that tags are supposed to be read-only, but it seems backwards to prevent people entirely from creating them because of the use of this weird edge-case of TypeScript unions. Is this truly the intended behavior? |
Hi! No, that was not intended. I gave it some time to try and fix it but I can't make it work. Maybe someone with a bit more TypeScript expertise knows how. |
Yeah, I took a look as well. The link suke posted above was also very helpful. There are a few issues open on the TS project and even some proposals to properly handle this, but it hasn't yet come to a resolution.
It looks like the workaround is actually to do this the way it is, and then use an mockExifLoad.mockResolvedValueOnce({
xmp: Object.assign({
_raw: "",
}, {
description: { attributes: {}, description: "My description", value: null as never },
} as XmpTags),
}); I guess we just have to hope for a future TypeScript version that gives us a better way to handle this. |
Description
Fix
tags.xmp._raw
type to string.Related to #183
Current behavior

Expected behavior
