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.
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.
Check that
valuehas exactlylengthelements 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 asT[]with lengthnumberand cannot be assigned toFixedArray<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.Returns a frozen copy rather than
valueitself. Returning the argument would leave the caller's reference aliasing the result, so a latersource.push(...)would change the length of a value whose type promisesN— the readonly type only stops mutation through theFixedArrayreference, 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.