function describeTypeOf()

in packages/@jsii/kernel/src/serialization.ts [1266:1305]


function describeTypeOf(
  value: unknown,
  isVisibleType: (fqn: string) => boolean,
) {
  const type = typeof value;
  switch (type) {
    case 'object':
      if (value == null) {
        return JSON.stringify(value);
      }

      if (Array.isArray(value)) {
        return 'an array';
      }

      const fqn = jsiiTypeFqn(value as object, isVisibleType);
      if (fqn != null && fqn !== EMPTY_OBJECT_FQN) {
        return `an instance of ${fqn}`;
      }

      const ctorName = (value as object).constructor.name;
      if (ctorName != null && ctorName !== Object.name) {
        return `an instance of ${ctorName}`;
      }

      return `an object`;

    case 'undefined':
      return type;

    case 'boolean':
    case 'function':
    case 'number':
    case 'string':
    case 'bigint':
    case 'symbol':
    default:
      return `a ${type}`;
  }
}