Skip to content

TypeScript: Camera.rotationQuaternion should allow null type #17463

@nsxdavid

Description

@nsxdavid

Description

The TypeScript type definition for Camera.rotationQuaternion (specifically in TargetCamera and its children) is incorrectly defined as non-nullable:

rotationQuaternion: Quaternion;

However, setting this property to null is documented, intentional behavior. According to Babylon.js patterns, setting rotationQuaternion = null is the standard way to disable quaternion-based rotation and allow the camera to use Euler angles (rotation property) instead.

Current Behavior

TypeScript incorrectly rejects this valid runtime code:

camera.rotationQuaternion = null;  // Type error: Type 'null' is not assignable to type 'Quaternion'

Expected Behavior

The type definition should allow null:

rotationQuaternion: Quaternion | null;

Current Workaround

(camera as {rotationQuaternion: Quaternion | null}).rotationQuaternion = null;

Impact

  • This is a type-only change that better reflects actual runtime behavior
  • May require users to add null checks when accessing the property, which is appropriate since it can actually be null at runtime
  • Improves type safety by preventing assumptions that this property is always defined

Version

  • Babylon.js: 8.26.0 (but appears present in latest versions as well)

Additional Context

This pattern (setting rotationQuaternion = null) is used throughout Babylon.js examples and is the recommended approach when you want the camera rig to control all orientation via parent transforms without local camera rotation.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions