From b2714ca87610dcfaf51b23a5f73c5cab582b416a Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Sun, 10 Apr 2022 20:13:53 +0200 Subject: [PATCH] Change all `typeof x === 'undefined' to `x === undefined` https://github.com/theatre-js/theatre/pull/118#discussion_r846634374 --- theatre/core/src/sheetObjects/SheetObject.ts | 4 ++-- theatre/shared/src/propTypes/utils.ts | 4 ++-- theatre/shared/src/utils/deepMergeWithCache.ts | 2 +- theatre/shared/src/utils/forEachDeep.ts | 2 +- theatre/studio/src/StudioStore/createTransactionPrivateApi.ts | 4 ++-- theatre/studio/src/store/stateEditors.ts | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/theatre/core/src/sheetObjects/SheetObject.ts b/theatre/core/src/sheetObjects/SheetObject.ts index 4fc7689..fafa7ff 100644 --- a/theatre/core/src/sheetObjects/SheetObject.ts +++ b/theatre/core/src/sheetObjects/SheetObject.ts @@ -164,7 +164,7 @@ export default class SheetObject implements IdentityDerivationProvider { const leftDeserialized = deserializeAndSanitize(triple.left) const left = - typeof leftDeserialized === 'undefined' + leftDeserialized === undefined ? propConfig.default : leftDeserialized @@ -173,7 +173,7 @@ export default class SheetObject implements IdentityDerivationProvider { const rightDeserialized = deserializeAndSanitize(triple.right) const right = - typeof rightDeserialized === 'undefined' + rightDeserialized === undefined ? propConfig.default : rightDeserialized diff --git a/theatre/shared/src/propTypes/utils.ts b/theatre/shared/src/propTypes/utils.ts index 3731b27..09e3382 100644 --- a/theatre/shared/src/propTypes/utils.ts +++ b/theatre/shared/src/propTypes/utils.ts @@ -20,7 +20,7 @@ export function getPropConfigByPath( ): undefined | PropTypeConfig { if (!parentConf) return undefined const [key, ...rest] = path - if (typeof key === 'undefined') return parentConf + if (key === undefined) return parentConf if (!isPropConfigComposite(parentConf)) return undefined const sub = @@ -44,7 +44,7 @@ export function valueInProp( ? T : never { const sanitizedVal = propConfig.deserializeAndSanitize(value) - if (typeof sanitizedVal === 'undefined') { + if (sanitizedVal === undefined) { return propConfig.default } else { return sanitizedVal diff --git a/theatre/shared/src/utils/deepMergeWithCache.ts b/theatre/shared/src/utils/deepMergeWithCache.ts index a2f4197..96f2b31 100644 --- a/theatre/shared/src/utils/deepMergeWithCache.ts +++ b/theatre/shared/src/utils/deepMergeWithCache.ts @@ -24,7 +24,7 @@ export default function deepMergeWithCache( merged[key] = typeof valueInOverride === 'object' && typeof valueInBase === 'object' ? deepMergeWithCache(valueInBase, valueInOverride, cache) - : typeof valueInOverride === 'undefined' + : valueInOverride === undefined ? valueInBase : valueInOverride } diff --git a/theatre/shared/src/utils/forEachDeep.ts b/theatre/shared/src/utils/forEachDeep.ts index 8d3ea2b..be188d1 100644 --- a/theatre/shared/src/utils/forEachDeep.ts +++ b/theatre/shared/src/utils/forEachDeep.ts @@ -12,7 +12,7 @@ export default function forEachDeep< for (const [key, value] of Object.entries(m)) { forEachDeep(value!, fn, [...startingPath, key]) } - } else if (typeof m === 'undefined' || m === null) { + } else if (m === undefined || m === null) { return } else { fn(m as $IntentionalAny as Primitive, startingPath) diff --git a/theatre/studio/src/StudioStore/createTransactionPrivateApi.ts b/theatre/studio/src/StudioStore/createTransactionPrivateApi.ts index 8fd5303..1f4ecd5 100644 --- a/theatre/studio/src/StudioStore/createTransactionPrivateApi.ts +++ b/theatre/studio/src/StudioStore/createTransactionPrivateApi.ts @@ -100,14 +100,14 @@ export default function createTransactionPrivateApi( propConfig: PropTypeConfig_AllNonCompounds, path: PathToProp, ) => { - if (typeof value === 'undefined' || value === null) { + if (value === undefined || value === null) { return } const deserialized = cloneDeepSerializable( propConfig.deserializeAndSanitize(value), ) - if (typeof deserialized === 'undefined') { + if (deserialized === undefined) { throw new Error( `Invalid value ${userReadableTypeOfValue( value, diff --git a/theatre/studio/src/store/stateEditors.ts b/theatre/studio/src/store/stateEditors.ts index ce555ed..d401009 100644 --- a/theatre/studio/src/store/stateEditors.ts +++ b/theatre/studio/src/store/stateEditors.ts @@ -58,7 +58,7 @@ export const setDrafts__onlyMeantToBeCalledByTransaction = ( let currentDrafts: undefined | Drafts const drafts = (): Drafts => { - if (typeof currentDrafts === 'undefined') { + if (currentDrafts === undefined) { throw new Error( `Calling stateEditors outside of a transaction is not allowed.`, )