FuelLabs/fuels-ts · error · FuelError
TYPE_NOT_SUPPORTED
TYPE_NOT_SUPPORTED
Error message
Invalid number type: ${baseType} What it means
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).
Source
Thrown at packages/abi-coder/src/encoding/coders/NumberCoder.ts:20
import { toNumber, toBytes } from '@fuel-ts/math';
import type { EncodingOptions } from '../../types/EncodingOptions';
import { WORD_SIZE } from '../../utils/constants';
import { Coder } from './AbstractCoder';
type NumberCoderType = 'u8' | 'u16' | 'u32';
const getLength = (baseType: NumberCoderType): number => {
switch (baseType) {
case 'u8':
return 1;
case 'u16':
return 2;
case 'u32':
return 4;
default:
throw new FuelError(ErrorCode.TYPE_NOT_SUPPORTED, `Invalid number type: ${baseType}`);
}
};
export class NumberCoder extends Coder<number, number> {
baseType: NumberCoderType;
options: EncodingOptions;
constructor(
baseType: NumberCoderType,
options: EncodingOptions = {
padToWordSize: false,
}
) {
const length = options.padToWordSize ? WORD_SIZE : getLength(baseType);
super('number', baseType, length);
this.baseType = baseType;
this.options = options;
}View on GitHub (pinned to b3f37c91ac)
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.
Example fix
// before
new NumberCoder('u64') // u64 is not a NumberCoder type
// after
import { BigNumberCoder } from './BigNumberCoder'
new BigNumberCoder('u64') // correct coder for u64 Defensive patterns
Strategy: type-guard
Validate before calling
const NUMBER_TYPES = new Set(['u8', 'u16', 'u32'])
if (!NUMBER_TYPES.has(baseType)) throw new Error(`use BigNumberCoder for ${baseType}`)
new NumberCoder(baseType as 'u8' | 'u16' | 'u32') Type guard
const isNumberCoderType = (t: string): t is 'u8' | 'u16' | 'u32' => t === 'u8' || t === 'u16' || t === 'u32'
Try / catch
try { new NumberCoder(baseType as any) }
catch (e) { if ((e as FuelError).code === ErrorCode.TYPE_NOT_SUPPORTED) { /* route u64/u256 to BigNumberCoder */ } throw e } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of FuelLabs/fuels-ts@b3f37c91ac (2026-08-12).
Data as JSON: /api/errors/0b271492c83368aa.
Report an issue: GitHub.