TypeScript Usage
TypeScript Usage
Section titled “TypeScript Usage”Strata is written in TypeScript and provides comprehensive type definitions.
Install Types
Section titled “Install Types”Three.js types are required:
pnpm add -D @types/threetsconfig.json
Section titled “tsconfig.json”Recommended configuration:
{ "compilerOptions": { "target": "ES2022", "module": "ESNext", "moduleResolution": "bundler", "strict": true, "jsx": "react-jsx", "esModuleInterop": true, "allowSyntheticDefaultImports": true, "skipLibCheck": true }}Importing Types
Section titled “Importing Types”import type { BiomeConfig, TerrainConfig, WaterConfig, SkyConfig, TimeOfDay, VegetationConfig, WindConfig, DeviceProfile, InputSnapshot,} from '@strata-game-library/core/types';Component Props
Section titled “Component Props”All components have typed props:
import { Water, type WaterProps } from '@strata-game-library/core';
const waterConfig: WaterProps = { size: 200, depth: 20, color: '#0077be', reflections: true,};
<Water {...waterConfig} />Generic Functions
Section titled “Generic Functions”Some functions are generic:
import { createPreset } from '@strata-game-library/presets';
interface CustomTerrainConfig extends TerrainConfig { crystalFormations: boolean;}
const preset = createPreset<CustomTerrainConfig>({ amplitude: 100, crystalFormations: true,});Strict Null Checks
Section titled “Strict Null Checks”Handle nullable refs properly:
const terrainRef = useRef<THREE.Mesh>(null);
useFrame(() => { if (terrainRef.current) { terrainRef.current.rotation.y += 0.01; }});Custom Extensions
Section titled “Custom Extensions”Extend existing types:
import type { BiomeConfig } from '@strata-game-library/core/types';
interface AlienBiomeConfig extends BiomeConfig { crystalDensity: number; glowIntensity: number;}
const alienBiome: AlienBiomeConfig = { name: 'alien', colors: { low: '#7b2cbf', mid: '#9d4edd', high: '#c77dff', cliff: '#5a189a' }, terrainShape: { amplitude: 100, frequency: 0.01, sharpness: 0.8 }, vegetation: { trees: false, grass: true }, crystalDensity: 0.3, glowIntensity: 0.5,};