fix(utils): add hasProperty back. 2x faster than Reflect.has

This commit is contained in:
Skillz4Killz
2022-05-28 13:39:46 +00:00
committed by GitHub
parent 28974f2497
commit 0aff36afbe
4 changed files with 35 additions and 7 deletions
+10
View File
@@ -13,3 +13,13 @@ export function delay(ms: number): Promise<void> {
export function formatImageURL(url: string, size: ImageSize = 128, format?: ImageFormat) {
return `${url}.${format || (url.includes("/a_") ? "gif" : "jpg")}?size=${size}`;
}
// Typescript is not so good as we developers so we need this little utility function to help it out
// Taken from https://fettblog.eu/typescript-hasownproperty/
/** TS save way to check if a property exists in an object */
export function hasProperty<T extends {}, Y extends PropertyKey = string>(
obj: T,
prop: Y,
): obj is T & Record<Y, unknown> {
return obj.hasOwnProperty(prop);
}