Logos DX
    Preparing search index...

    Function definePublicProps

    • Defines visible, non-configurable properties on an object.

      Creates properties that are enumerable (show up in for...in loops and Object.keys) but cannot be modified or deleted. Useful for creating public APIs.

      Type Parameters

      • T
      • U extends Record<string, unknown>

      Parameters

      • target: T

        object to add properties to

      • props: U

        properties to define

      • configurable: boolean = false

        whether properties can be deleted or reconfigured

      Returns void

      const api = {};
      definePublicProps(api, {
      version: '1.0.0',
      name: 'MyAPI'
      });

      console.log(api.version); // '1.0.0'
      console.log(Object.keys(api)); // ['version', 'name']
      api.version = '2.0.0'; // Fails silently or throws in strict mode
      class DataProcessor {
      constructor(config) {
      definePublicProps(this, {
      id: crypto.randomUUID(),
      createdAt: new Date()
      });
      }
      }