{"record":{"id":"37df46eb62abb8a3","repo":"clockworklabs/SpacetimeDB","slug":"cannot-convert-typeof-value-to-what-expecte","errorCode":null,"errorMessage":"Cannot convert ${typeof value} to ${what}: expected bigint, integer number, or decimal string","messagePattern":"Cannot convert (.+?) to (.+?): expected bigint, integer number, or decimal string","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crates/bindings-typescript/src/lib/util.ts","lineNumber":115,"sourceCode":"}\n\n/**\n * Coerces a value that should be a `bigint` — but may arrive as a `number`\n * or decimal string after passing through JSON — into a `bigint`.\n *\n * Every other type is rejected up front: bare `BigInt()` would silently\n * accept booleans (`true` → `1n`), arrays (`[42]` → `42n`) and empty\n * strings (`'' ` → `0n`), turning malformed payloads into valid-looking\n * ids instead of failing early.\n *\n * @param value The value to coerce\n * @param what Type name used in the error message (e.g. `'ConnectionId'`)\n */\nexport function coerceToBigInt(value: unknown, what: string): bigint {\n  if (typeof value === 'bigint') return value;\n  if (typeof value === 'number') return BigInt(value);\n  if (typeof value === 'string' && value.trim() !== '') return BigInt(value);\n  throw new TypeError(\n    `Cannot convert ${typeof value} to ${what}: expected bigint, integer number, or decimal string`\n  );\n}\n\n/**\n * Converts a string to PascalCase (UpperCamelCase).\n * @param str The string to convert\n * @returns The converted string\n */\nexport function toPascalCase(s: string): string {\n  const str = toCamelCase(s);\n  return str.charAt(0).toUpperCase() + str.slice(1);\n}\n\n/**\n * Type safe conversion from a string like \"some_identifier-name\" to \"someIdentifierName\".\n * @param str The string to convert\n * @returns The converted string","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/6dee26c6efc2856793e12b148a59742964f5d783/crates/bindings-typescript/src/lib/util.ts#L97-L133","documentation":"Column-attribute validation rejects #[default(...)] on a column that also carries #[auto_inc], #[primary_key], or #[unique]. Those attributes determine the column's value authoritatively (sequence generation, key identity, uniqueness), so a user-supplied default would conflict; the error is spanned to the default expression.","triggerScenarios":"A field combining #[default(...)] with any of #[auto_inc], #[primary_key], or #[unique] — e.g. #[unique] #[default(0)] pub id: u64.","commonSituations":"Adding defaults for not-null convenience on id columns; habits carried over from ORMs where primary keys have defaults.","solutions":["Remove #[default(...)] from the auto_inc/primary_key/unique column.","If the default genuinely matters, drop the conflicting attribute — but auto-increment ids and primary keys almost always win.","Put #[default(...)] on plain data columns instead."],"exampleFix":"// before\n#[primary_key]\n#[auto_inc]\n#[default(0)]\npub id: u64,\n\n// after\n#[primary_key]\n#[auto_inc]\npub id: u64,","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never combine #[default(...)] with #[auto_inc], #[primary_key], or #[unique] on one field.","Reserve #[default(...)] for plain data columns.","Review column attributes as a set: key/uniqueness attributes own the value; defaults must not fight them."],"tags":["spacetimedb","proc-macro","table","default-value","column-attributes","compile-time"],"backgroundTag":"conflicting-column-attributes","analyzedSha":"6dee26c6efc2856793e12b148a59742964f5d783","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}