{"record":{"id":"0b271492c83368aa","repo":"FuelLabs/fuels-ts","slug":"type-not-supported","errorCode":"TYPE_NOT_SUPPORTED","errorMessage":"Invalid number type: ${baseType}","messagePattern":"Invalid number type: (.+?)","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/abi-coder/src/encoding/coders/NumberCoder.ts","lineNumber":20,"sourceCode":"import { toNumber, toBytes } from '@fuel-ts/math';\n\nimport type { EncodingOptions } from '../../types/EncodingOptions';\nimport { WORD_SIZE } from '../../utils/constants';\n\nimport { Coder } from './AbstractCoder';\n\ntype NumberCoderType = 'u8' | 'u16' | 'u32';\n\nconst getLength = (baseType: NumberCoderType): number => {\n  switch (baseType) {\n    case 'u8':\n      return 1;\n    case 'u16':\n      return 2;\n    case 'u32':\n      return 4;\n    default:\n      throw new FuelError(ErrorCode.TYPE_NOT_SUPPORTED, `Invalid number type: ${baseType}`);\n  }\n};\n\nexport class NumberCoder extends Coder<number, number> {\n  baseType: NumberCoderType;\n  options: EncodingOptions;\n\n  constructor(\n    baseType: NumberCoderType,\n    options: EncodingOptions = {\n      padToWordSize: false,\n    }\n  ) {\n    const length = options.padToWordSize ? WORD_SIZE : getLength(baseType);\n    super('number', baseType, length);\n    this.baseType = baseType;\n    this.options = options;\n  }","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/abi-coder/src/encoding/coders/NumberCoder.ts#L2-L38","documentation":"Thrown inside NumberCoder's getLength helper (constructor path) when baseType is not 'u8', 'u16', or 'u32'. Message: \"Invalid number type: <baseType>\". Code is TYPE_NOT_SUPPORTED. NumberCoderType is a TypeScript union, so at the type level this is unreachable — it fires only when a non-union string reaches the constructor at runtime (e.g. via 'as any', a cast, or a dynamically-built type string).","triggerScenarios":"Constructing new NumberCoder('u64') or any string other than u8/u16/u32 — most commonly passing 'u64'/'u256' (which belong to BigNumberCoder) or a malformed type token. Also reachable by casting arbitrary strings through 'as NumberCoderType' or building types dynamically.","commonSituations":"Confusing NumberCoder (u8/u16/u32) with BigNumberCoder (u64/u256); auto-generating coders from type strings without filtering; old code that assumed a wider set; a typo in the baseType literal.","solutions":["Use NumberCoder only for u8, u16, or u32; use BigNumberCoder for u64 and u256.","If you build coders from type strings, route u64/u256 to BigNumberCoder explicitly.","Constrain the baseType at the type level and avoid 'as any' casts."],"exampleFix":"// before\nnew NumberCoder('u64') // u64 is not a NumberCoder type\n\n// after\nimport { BigNumberCoder } from './BigNumberCoder'\nnew BigNumberCoder('u64') // correct coder for u64","handlingStrategy":"type-guard","validationCode":"const NUMBER_TYPES = new Set(['u8', 'u16', 'u32'])\nif (!NUMBER_TYPES.has(baseType)) throw new Error(`use BigNumberCoder for ${baseType}`)\nnew NumberCoder(baseType as 'u8' | 'u16' | 'u32')","typeGuard":"const isNumberCoderType = (t: string): t is 'u8' | 'u16' | 'u32' =>\n  t === 'u8' || t === 'u16' || t === 'u32'","tryCatchPattern":"try { new NumberCoder(baseType as any) }\ncatch (e) { if ((e as FuelError).code === ErrorCode.TYPE_NOT_SUPPORTED) { /* route u64/u256 to BigNumberCoder */ } throw e }","preventionTips":["Remember: NumberCoder = u8/u16/u32; BigNumberCoder = u64/u256.","When building coders from type strings, branch on the size class.","Avoid 'as any' casts on baseType."],"tags":["abi-coder","encoding","number","type-mismatch","config"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}