Skip to content

typeOf

const typeOf: TypeOf

Defined in: packages/typegpu/src/std/typeOf.ts:36

Returns the type of an expression, the one it will have during shader execution. That information can be used to introspect or specialize the shader. It will return undefined if the expression cannot be represented in shader code, or if the type is unknown at the point where the query is made.

The returned value is only known at shader-generation time and has no WGSL representation, so it cannot be stored in a variable (e.g. const t = std.typeOf(a) throws). Consume it immediately, e.g. by comparing it (std.typeOf(a) === d.f32) or passing it to a comptime function.

function double(value: number) {
'use gpu';
if (std.typeOf(value) === d.f32) {
return value * 2;
}
return value << 1;
}
function main() {
'use gpu';
double(1.5); // generates double(f32), which multiplies by 2
double(1); // generates double(i32), which shifts left by 1
}

© Software Mansion 2026. All trademarks and copyrights belong to their respective owners. Read about our Privacy Policy.