Skip to content
Work in progress. These docs describe Spawnite at launch, and some parts are still being built.

DeepReadonly

DeepReadonly<T> = T extends Entity ? T : T extends string | number | boolean | bigint | symbol ? T : typeof liveObjectBrand extends keyof T ? T : T extends Object3D ? T : T extends Vector3 ? ReadonlyVector3 : T extends Quaternion ? ReadonlyQuaternion : T extends Vector2 ? ReadonlyVector2 : T extends Euler ? ReadonlyEuler : T extends Color ? ReadonlyColor : T extends Matrix4 ? ReadonlyMatrix4 : … extends … ? … : …

T with no field a reader can change, at any depth, and three’s vectors and quaternions as their read-only views. A mapped type leaves a class’s own methods callable, so another class’s methods that write, such as a Color’s set, stay callable: the type does not cover them. A scene object, such as the Object3D a view holds in RefTrait, is the view’s own to move, and stays as it is, and so does a field typed LiveObject, for a handle a game keeps, such as an AnimationMixer. An entity keeps its brand, such as a PlayerEntity, and so does a branded id, such as a PlayerId.

Type Parameter
T