Closed reefdog closed 2 months ago
Now that I'm actually digging into this, this is due to the signature of Object.entries
, not due to our type definition.
Object.entries cannot safely guarantee that values are always of a given type -- even if the "Type" of a given variable has only string entities documented, TypeScript is not saying there aren't more than those entities on the object (nor does it indicate what those entities will be).
So I think what we'll need to do is add a type guard e.g.:
const isStringOrBlob(value: unknown) value is string | Blob => typeof value === 'string' || value instanceof Blob
Object.entries(presignedPost.fields).forEach(([key, value]) =>
if (isValidFormDataValue(value) {
formData.append(key, value),
}
);
Here's the definition of ObjectConstructor.entries
in es2017:
/**
* Returns an array of key/values of the enumerable properties of an object
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
*/
entries(o: {}): [string, any][];
^ note the any
there
For now I'm marking this as closed as not planned based on the above analysis, that said we can absolutely re-open if that is wrong.
This makes sense! Thanks for the thorough explanation and even tackling the front-end issue that this is linked to! 🙏
When using the
PresignedPostRequestPresignedPost
type, accessing the values from a presigned postfields
object triggers the ol' unsafeany
type complaint:E.g.:
Unsure if this should be part of https://github.com/PhilanthropyDataCommons/service/issues/1004 or is separate.