isScalar
On this page

isScalar()

Function in Types

Narrows a ShaderType to the native { kind: 'scalar' } arm.

import { isScalar } from 'typeshade'
import { isScalar } from 'typeshade/core/ir'

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

Syntax

const isScalar: (
t: ShaderType,
) => t is Extract<ShaderType, { kind: "scalar"; }>

Parameters

t ShaderType

Return value

t is Extract<ShaderType, { kind: 'scalar' }>

Description

Narrows a ShaderType to the native { kind: 'scalar' } arm (f32, i32, u32, bool). It is false for f64T, which is its own kind so that this predicate does not treat it as a scalar. Arithmetic type resolution uses it to detect the vector-scalar broadcast case (isVec(a) && isScalar(b) and its mirror), where the vector operand’s type is the result.

Examples

Example

import { isScalar } from 'typeshade'
import { f32T, f64T } from 'typeshade/core/ir'
isScalar(f32T) // true
isScalar(f64T) // false: f64 is its own ShaderType kind

See also

Source

src/core/ir/types/predicates.ts, line 39, at commit af54ddad5

Edit this page Report a problem