{"record":{"id":"1ac00b4412786c65","repo":"withastro/astro","slug":"key-expects-a-defaulttype-value","errorCode":null,"errorMessage":"${key} expects a \"${defaultType}\" value!","messagePattern":"(.+?) expects a \"(.+?)\" value!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/astro/src/cli/preferences/index.ts","lineNumber":164,"sourceCode":"\t\t\tconsole.log(msg.preferenceDefault(key, defaultValue));\n\t\t\treturn 0;\n\t\t}\n\t\tconsole.log(msg.preferenceGet(key, value));\n\t\treturn 0;\n\t} catch {}\n\treturn 1;\n}\n\nasync function setPreference(\n\tsettings: AstroSettings,\n\tkey: PreferenceKey,\n\tvalue: unknown,\n\t{ location }: SubcommandOptions,\n) {\n\ttry {\n\t\tconst defaultType = typeof dlv(DEFAULT_PREFERENCES, key);\n\t\tif (typeof coerce(key, value) !== defaultType) {\n\t\t\tthrow new Error(`${key} expects a \"${defaultType}\" value!`);\n\t\t}\n\n\t\tawait settings.preferences.set(key, coerce(key, value), { location });\n\t\tconsole.log(msg.preferenceSet(key, value));\n\t\treturn 0;\n\t} catch (e) {\n\t\tif (e instanceof Error) {\n\t\t\tconsole.error(msg.formatErrorMessage(collectErrorMetadata(e), true));\n\t\t\treturn 1;\n\t\t}\n\t\tthrow e;\n\t}\n}\n\nasync function enablePreference(\n\tsettings: AstroSettings,\n\tkey: PreferenceKey,\n\t{ location }: SubcommandOptions,","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/cli/preferences/index.ts#L146-L182","documentation":"The `astro preferences set <key> <value>` subcommand compares the runtime type of the coerced value against the type of the default value stored in `DEFAULT_PREFERENCES` (looked up via `dlv`). If `coerce(key, value)` does not produce the expected `boolean`/`string`/`number`, the set is rejected before persisting. This keeps preference files internally consistent.","triggerScenarios":"Calling `astro preferences set devToolbar.enabled notabool` for a boolean preference (default type is `boolean`, coerced string is `string`); passing a non-numeric value to a numeric preference; passing a string to a preference whose default is an object/`undefined`.","commonSituations":"Assuming a preference is a string when it is actually boolean (e.g. `devToolbar.enabled`); quoting values that get coerced to strings unexpectedly; copying a value from docs without checking its declared type in `DEFAULT_PREFERENCES`.","solutions":["Inspect the expected type: `astro preferences get <key>` and read the default printed, or check `packages/astro/src/preferences/defaults.ts`.","For boolean preferences use `astro preferences enable <key>` / `disable <key>` instead of `set`.","Supply a literal of the correct type (e.g. `astro preferences set <key> true` for booleans, a number for numeric keys).","Use `astro preferences reset <key>` to restore a known-good default if you are unsure what the value should be."],"exampleFix":"# before\n$ astro preferences set devToolbar.enabled yes\n# after\n$ astro preferences enable devToolbar\n# or\n$ astro preferences set devToolbar.enabled true","handlingStrategy":"validation","validationCode":"import dlv from 'astro/preferences/dlv'; // illustrative\nconst defaultType = typeof dlv(DEFAULT_PREFERENCES, key);\nif (typeof coerce(key, value) !== defaultType) {\n  throw new Error(`Pass a ${defaultType} for ${key}`);\n}","typeGuard":"function isPreferenceValue(key, value) {\n  const map = { 'devToolbar.enabled': 'boolean', 'devToolbar.open': 'boolean' };\n  return typeof value === (map[key] ?? 'string');\n}","tryCatchPattern":null,"preventionTips":["Use `astro preferences enable`/`disable` for booleans instead of `set`.","Run `astro preferences get <key>` to learn the expected type before setting.","Check `packages/astro/src/preferences/defaults.ts` for the canonical types."],"tags":["cli","preferences","type-mismatch","validation"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}