sparkengineweb
    Preparing search index...

    Function Optional

    • Type Parameters

      • T

      Parameters

      • type: T

        The runtime class/constructor that represents the property's type. For type aliases, use the base runtime class they resolve to.

      Returns PropertyDecorator

      // For direct class types:
      class MaterialComponent {
      @Optional(Rgb)
      diffuseColor?: Rgb;
      }

      // For type aliases, use the base runtime class:
      // type CollisionCallback = SerializableCallback<...>
      class BoundingBoxComponent {
      @Optional(SerializableCallback) // Use runtime class, not alias
      onCollision?: CollisionCallback; // Type annotation can use alias
      }

      const material = new MaterialComponent();
      getOptionalType(material, 'diffuseColor') // Returns Rgb
      getOptionalType(material, 'onCollision') // Returns SerializableCallback