{"record":{"id":"5a45e7fe4325aca8","repo":"sveltejs/svelte","slug":"cannot-spring-typeof-current-value-values","errorCode":null,"errorMessage":"Cannot spring ${typeof current_value} values","messagePattern":"Cannot spring (.+?) values","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/svelte/src/motion/spring.js","lineNumber":55,"sourceCode":"\t\t\t// @ts-ignore\n\t\t\treturn is_date(current_value) ? new Date(current_value.getTime() + d) : current_value + d;\n\t\t}\n\t} else if (Array.isArray(current_value)) {\n\t\t// @ts-ignore\n\t\treturn current_value.map((_, i) =>\n\t\t\t// @ts-ignore\n\t\t\ttick_spring(ctx, last_value[i], current_value[i], target_value[i])\n\t\t);\n\t} else if (typeof current_value === 'object') {\n\t\tconst next_value = {};\n\t\tfor (const k in current_value) {\n\t\t\t// @ts-ignore\n\t\t\tnext_value[k] = tick_spring(ctx, last_value[k], current_value[k], target_value[k]);\n\t\t}\n\t\t// @ts-ignore\n\t\treturn next_value;\n\t} else {\n\t\tthrow new Error(`Cannot spring ${typeof current_value} values`);\n\t}\n}\n\n/**\n * The spring function in Svelte creates a store whose value is animated, with a motion that simulates the behavior of a spring. This means when the value changes, instead of transitioning at a steady rate, it \"bounces\" like a spring would, depending on the physics parameters provided. This adds a level of realism to the transitions and can enhance the user experience.\n *\n * @deprecated Use [`Spring`](https://svelte.dev/docs/svelte/svelte-motion#Spring) instead\n * @template [T=any]\n * @param {T} [value]\n * @param {SpringOptions} [opts]\n * @returns {SpringStore<T>}\n */\nexport function spring(value, opts = {}) {\n\tconst store = writable(value);\n\tconst { stiffness = 0.15, damping = 0.8, precision = 0.01 } = opts;\n\t/** @type {number} */\n\tlet last_time;\n\t/** @type {Task | null} */","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/sveltejs/svelte/blob/20b341f10048cf1016a2028ac7eee5595cfef6a5/packages/svelte/src/motion/spring.js#L37-L73","documentation":"Svelte's `spring()` store animates values by ticking them toward a target. `tick_spring` only interpolates numbers, `Date`s, arrays (of interpolables), and plain objects (of interpolables). Any other type — `string`, `boolean`, `function`, `symbol`, `bigint` — falls through to the throw. The deprecated `spring()` store is the affected API.","triggerScenarios":"Creating `spring(initialValue)` where `initialValue` is a string, boolean, or function; or calling `.set(newValue)` where the new value's type isn't number/date/array/object.","commonSituations":"Animating a color string with `spring` (use `tweened` with an interpolator or a color tween instead); initializing `spring` with `null`/`undefined`; mixing types across `.set()` calls.","solutions":["Use numeric values: animate numbers or arrays of numbers.","For colors or strings, use `tweened()` with a custom interpolator instead of `spring()`.","Ensure `.set()` always receives the same type as the initial value."],"exampleFix":"// before\nconst color = spring('#fff'); // string -> throws\ncolor.set('#000');\n// after -- animate numeric channels\nconst r = spring(255); r.set(0);\n// or use tweened for strings\nimport { tweened } from 'svelte/motion';\nconst color = tweened('#fff');","handlingStrategy":"type-guard","validationCode":"function isSpringable(v) {\n\treturn typeof v === 'number' || v instanceof Date || Array.isArray(v) || (typeof v === 'object' && v !== null);\n}\nif (!isSpringable(value)) throw new Error('spring requires a number, Date, array, or object');","typeGuard":"function isSpringable(v) {\n\tif (typeof v === 'number' || v instanceof Date) return true;\n\tif (Array.isArray(v)) return v.every(isSpringable);\n\tif (v !== null && typeof v === 'object') return Object.values(v).every(isSpringable);\n\treturn false;\n}","tryCatchPattern":null,"preventionTips":["Only animate numbers, Dates, arrays, or objects with `spring`.","Use `tweened` with a custom interpolator for strings/colors.","Keep spring value types stable across `.set()` calls.","Prefer the new `Spring` class over the deprecated `spring()` function."],"tags":["spring","motion","animation","type","svelte-motion"],"backgroundTag":null,"analyzedSha":"20b341f10048cf1016a2028ac7eee5595cfef6a5","analyzedAt":"2026-08-12T23:37:30.399Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}