[v10][tsl] Generate the uniforms Register declaration with a Vite plugin

Author: DennisSmolekCreated Sep 25, 2026Updated Sep 25, 2026
LabelsTypescriptv10

Summary

A Vite plugin (optional, opt-in) that writes the declare module '@react-three/tsl' { interface Register { ... } } file for you, the way TanStack Router generates routeTree.gen.ts. Users then get useUniforms().uMyColor and frame-loop reads typed everywhere without writing the declaration by hand.

Background

The planned @react-three/tsl package types uniforms globally through a Register interface that users augment:

typescript
declare module '@react-three/tsl' {
  interface Register {
    uniforms: typeof globalUniforms
    scopes: { player: typeof playerUniforms }
  }
}

That works, but you have to write and maintain the declaration yourself. TypeScript can't infer it from useUniforms(...) calls, because types follow imports, not what code does at runtime. The only way to skip the declaration is to generate it.

Sketch

  • The plugin scans for exported uniform definitions (see #3955) and writes a .gen.d.ts that references them with typeof import('./sky').sky. Definitions written inline inside components can't be referenced from a generated file, so this depends on exported definitions.
  • It regenerates on HMR and in vite build.
  • It reports conflicts when two definitions register the same root-level name with different types.

When

Only if people ask for it after Register and importable objects (#3955) ship. It's polish on top of those, not a prerequisite. Related: #3769.

Source: pmndrs/react-three-fiber