This page is for your editor and CI. A preview renders whether or not it typechecks, because esbuild strips types. You’ll add a second tsconfig for the preview, next to the one that builds your Luau.
rbxtsc uses that file to build the game. Editing it to make the preview typecheck breaks the build
you ship.
The ambient globals
Add one side-effect import to declare the Roblox globals and the JSX elements:
import "@loom-dev/preview/globals";Put the file inside the directory your preview tsconfig includes. It declares the datatypes
(UDim2, Color3, Rect, CFrame, TweenInfo, Enum, Instance, game and the rest) and the
Luau environment (task, math, string, os, coroutine, typeIs, pcall, pairs,
tostring, error, warn).
Two things look odd but are deliberate:
printis not declared, becauselib.domalready declares one and redeclaring it is an error.print(...)still works at runtime; it just types as the DOM’s zero-argument version.stringis also a global value, Luau’s string library. It doesn’t change thestringtype.
A real roblox-ts project gets similar declarations from @rbxts/compiler-types. Don’t include both
in one program.
JSX intrinsics
The same import declares the lowercase elements. The set is exactly what the renderer implements:
screengui surfacegui billboardguiframe scrollingframe canvasgroup viewportframe videoframetextlabel textbutton textboximagelabel imagebuttonuilistlayout uigridlayout uitablelayout uipagelayoutuipadding uicorner uistroke uishadow uiscale uigradientuiaspectratioconstraint uisizeconstraint uiflexitemAnything else is a type error and won’t render. See Supported instances and properties.
Teaching the editor about @rbxts/*
Add ambient module declarations that mirror the plugin’s runtime aliases:
declare module "@rbxts/react" { export * from "react"; export { default } from "react";}
declare module "@rbxts/react/jsx-runtime" { export * from "react/jsx-runtime";}
declare module "@rbxts/react-roblox" { export * from "@loom-dev/preview/client";}A top-level import or export turns declare module into an augmentation, which errors on a
module that doesn’t exist. That’s why the globals import lives in its own file.
Then the preview tsconfig:
{ "compilerOptions": { "noEmit": true, "jsx": "react-jsx", "moduleResolution": "bundler", "types": ["vite/client", "react"] }, "include": ["src"]}jsx: "react-jsx" matches the automatic JSX runtime the plugin uses, so you don’t need a React
import.
React.Event and React.Change work at runtime but type as errors, because @rbxts/react re-exports
plain React’s types. Use the Event={{ Activated: fn }} prop form instead.
These mappings also work, but they hard-code a node_modules layout and bypass the package’s
exports map:
"baseUrl": ".","paths": { "@rbxts/react": ["./node_modules/@types/react"], "@rbxts/react-roblox": ["./node_modules/@loom-dev/preview/src/client.ts"]}Workspace packages and your own aliases
If your preview app imports your UI library by workspace name, the library needs no paths entry.
TypeScript follows the workspace link, and loom resolves the package to its TypeScript source at
runtime.
The plugin also reads baseUrl and paths from your tsconfig.json, so non-relative imports like
import { Button } from "@/ui/Button" resolve at runtime too.
Typechecking is optional
A preview that never runs tsc still renders. Adding tsc --noEmit to CI catches broken scenes
early, at the cost of a second tsconfig to maintain. It’s worth it when your previews double as
documentation.