Thruput TypeScript protocol bindings
    Preparing search index...

    Function fixedArray

    • Check that value has exactly length elements and return it as a FixedArray.

      A fixed length is a literal type, so an array built at runtime — Array.from, map, an array literal — is inferred as T[] with length number and cannot be assigned to FixedArray<T, N> directly. This is the checked construction path: it validates the length and returns the narrowed type, so callers get a compile-time guarantee without writing a cast.

      const keys = fixedArray(
      Array.from({ length: 21 }, () => publicKeyConfigOpt(null)),
      21,
      );

      Returns a frozen copy rather than value itself. Returning the argument would leave the caller's reference aliasing the result, so a later source.push(...) would change the length of a value whose type promises N — the readonly type only stops mutation through the FixedArray reference, not through a retained alias. Freezing also holds the invariant for callers who reach the value through a cast or from plain JavaScript, where the type is not enforced at all. The copy is O(N), which is immaterial for the small fixed arrays XDR declares.

      Type Parameters

      • T
      • N extends number

      Parameters

      • value: readonly T[]
      • length: N

      Returns FixedArray<T, N>

      if value.length !== length.