array
Function
Builds an array<T, N> from exactly N values of type T.
The signature and the sentence under each name are the compiler's own text at commit 26de7be8.
Syntax
declare function array<V extends readonly unknown[]>(...values: V): array<[(V[number] extends infer E ? (E extends number ? (typeof f32Tag extends keyof E ? E : typeof i32Tag extends keyof E ? E : typeof u32Tag extends keyof E ? E : typeof f64Tag extends keyof E ? E : never) : never) : never)] extends [never] ? V[number] : (V[number] extends infer E ? (E extends number ? (typeof f32Tag extends keyof E ? E : typeof i32Tag extends keyof E ? E : typeof u32Tag extends keyof E ? E : typeof f64Tag extends keyof E ? E : never) : never) : never), V['length']>declare function array<T, N extends number>(...values: readonly T[]): array<T, N>A number in a parameter or a return position is the scalar slot. The ambient file declares a GPU scalar as a branded number whose brand is optional, so a literal and any branded scalar both fill it.
type f32 = number & { readonly [f32Tag]?: true }
A declaration you write still needs a width, and a bare number on a field or a parameter is refused; the TypeScript constructs page carries that row with the compiler's own message.
Parameters
-
...valuesVreadonly T[]
Return value
array<[(V[number] extends infer E ? (E extends number ? (typeof f32Tag extends keyof E ? E : typeof i32Tag extends keyof E ? E : typeof u32Tag extends keyof E ? E : typeof f64Tag extends keyof E ? E : never) : never) : never)] extends [never] ? V[number] : (V[number] extends infer E ? (E extends number ? (typeof f32Tag extends keyof E ? E : typeof i32Tag extends keyof E ? E : typeof u32Tag extends keyof E ? E : typeof f64Tag extends keyof E ? E : never) : never) : never), V['length']>array<T, N>
Description
Without type arguments, array(v1, v2, ..., vN) reads T and N off the values, as WGSL does; array<T, N>(v1, ..., vN) names them. An array has the methods map, forEach, some, every and reduce, each a counted loop over its elements that calls the function it is handed with the element, its i32 index and the array.
Examples
bare-position.shade.tsid-pick.shade.tsclip-planes.shade.tsarray-length.shade.tsshadow-compare.shade.tscube-env.shade.tscube-array-gather.shade.tsmsaa-resolve.shade.tsuniform-array.shade.tspalette-const.shade.tsarray-literal-ramp.shade.tspick-composite.shade.tsdefault-args.shade.tsbit-bump.shade.tsbool-select.shade.tsinteger-math.shade.tspacking-bitcast.shade.tspacked-bytes.shade.tsclosures.shade.tshigher-order.shade.tsarray-methods.shade.tsloops-over-data.shade.tspath-tracer.shade.tscapsule-corp-namek-class.shade.tsray-class.shade.tsorbit-inout.shade.tsparticle-step.shade.tsshape-inheritance.shade.tsmixin-surface.shade.tsgeneric-helpers.shade.tsgeneric-class.shade.tstuple-and-brand.shade.tsworkgroup-scratch.shade.tsworkgroup-reduce.shade.tsatomic-histogram.shade.tsgpu-console.shade.tscompute-sync.shade.tscompute-reduction-twin.shade.tsworkgroup-tile-2d.shade.tsloop-kernel.shade.tsloop-reduction.shade.tsloop-struct-array.shade.tsloop-on-cpu.shade.ts