Jaaneek
04/05/2022, 9:49 PMts
{Key:string}
instead it infers it to be:
ts
{ Key: string } | null
Me and my friend researched this further and came to conclusion that almost all of the storage methods are wrongly typed, they are being cast wrongly. We think its due to typescript version 4.07 which is bugged, we will make pull request and ask you to update typescript version aswell.
This is the bug we are talking about : https://github.com/microsoft/TypeScript/issues/48037
This is example of wrongly typed method in the storage library:
ts
getPublicUrl(
path: string
): {
data: { publicURL: string } | null
error: Error | null
publicURL: string | null
} {
try {
const _path = this._getFinalPath(path)
const publicURL = `${this.url}/object/public/${_path}`
const data = { publicURL }
return { data, error: null, publicURL }
} catch (error) {
return { data: null, error, publicURL: null }
}
}
Is typed as:
ts
{
data: { publicURL: string } | null
error: Error | null
publicURL: string | null
}
But should be:
ts
{
data: null;
error: Error;
publicURL: null;
}
| {
data: { publicURL: string };
error: null;
publicURL: string;
};
This is a huge inconvenience for users of this library and requires people that want to use typescript correctly to write a lot of boilerplate.jonny
04/06/2022, 4:01 AMjonny
04/06/2022, 4:06 AM{ Key: string } | null
and types that include null are perhaps because the request made with the user's authorization might not have permission to read/write that storage bucket path because of a row level security policy. So in that circumstance, it might be possible to have no error, but also return null, since that user fails the policy check.
I can't really comment on wether that is ideal DX, but perhaps that is why there are optional null types.
Again, this isn't really my area but that would be my guess.Jaaneek
04/06/2022, 9:31 AMJaaneek
04/06/2022, 9:32 AM