diff --git a/src/runtime/internal/utils.ts b/src/runtime/internal/utils.ts index 46df7aa0bc..928882552a 100644 --- a/src/runtime/internal/utils.ts +++ b/src/runtime/internal/utils.ts @@ -11,7 +11,7 @@ export function assign(tar: T, src: S): T & S { } export function is_promise(value: any): value is PromiseLike { - return value && typeof value === 'object' && typeof value.then === 'function'; + return value && typeof value === 'object' && is_function(value.then); } export function add_location(element, file, line, column, char) { @@ -33,7 +33,7 @@ export function is_function(thing: any): thing is Function { } export function safe_not_equal(a, b) { - return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); + return a != a ? b == b : a !== b || ((a && typeof a === 'object') || is_function(a)); } export function not_equal(a, b) { @@ -45,7 +45,7 @@ export function is_empty(obj) { } export function validate_store(store, name) { - if (store != null && typeof store.subscribe !== 'function') { + if (store != null && !is_function(store.subscribe)) { throw new Error(`'${name}' is not a store with a 'subscribe' method`); } } diff --git a/src/runtime/motion/tweened.ts b/src/runtime/motion/tweened.ts index 83434cdff6..8fa5ebaba6 100644 --- a/src/runtime/motion/tweened.ts +++ b/src/runtime/motion/tweened.ts @@ -1,5 +1,5 @@ import { Readable, writable } from 'svelte/store'; -import { assign, loop, now, Task } from 'svelte/internal'; +import { assign, is_function, loop, now, Task } from 'svelte/internal'; import { linear } from 'svelte/easing'; import { is_date } from './utils'; @@ -111,7 +111,7 @@ export function tweened(value?: T, defaults: Options = {}): Tweened { if (!started) { fn = interpolate(value, new_value); - if (typeof duration === 'function') duration = duration(value, new_value); + if (is_function(duration)) duration = duration(value, new_value); started = true; } diff --git a/src/runtime/transition/index.ts b/src/runtime/transition/index.ts index 7e879cb941..dbddfcc874 100644 --- a/src/runtime/transition/index.ts +++ b/src/runtime/transition/index.ts @@ -186,7 +186,7 @@ export function draw(node: SVGElement & { getTotalLength(): number }, { } else { duration = len / speed; } - } else if (typeof duration === 'function') { + } else if (is_function(duration)) { duration = duration(len); }