Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-opus-4-20250514· AnthropicHugging Face LMArena Human Preference 140K

--- import SchemaOrg from "./SchemaOrg.astro"; export interface FAQItem { question:…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with DeepSeekdeepseek-r1-0528’s answer.
  1. User

    import SchemaOrg from "./SchemaOrg.astro";

    export interface FAQItem { question: string; answer: string; }

    export interface Props { title?: string; items: FAQItem[]; }

    const { title = "Frequently Asked Questions", items } = Astro.props;

    <div
      class="max-w-3xl mx-auto divide-y divide-gray-200 dark:divide-gray-700"
    >
      {
        items.map((item, index) => (
          <div class="py-5 faq-item">
            <button
              class="flex w-full justify-between items-center text-left focus:outline-none"
              aria-expanded="false"
              aria-controls={`faq-${index}`}
            >
              <h3 class="font-heading font-semibold text-lg pr-6">
                {item.question}
              </h3>
              <span class="flex-shrink-0 ml-2">
                <svg
                  xmlns="http://www.w3.org/2000/svg"
                  class="h-5 w-5 transform transition-transform duration-200 faq-icon"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke="currentColor"
                >
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    stroke-width="2"
                    d="M19 9l-7 7-7-7"
                  />
                </svg>
              </span>
            </button>
            <div
              id={`faq-${index}`}
              class="mt-2 text-gray-600 dark:text-gray-400 faq-content hidden"
            >
              <p set:html={item.answer} />
            </div>
          </div>
        ))
      }
    </div>
    

    <SchemaOrg type="faq" data={{ questions: items, }} />

    Property 'style' does not exist on type 'Element'

  2. Claude Assistant

    The TypeScript error you're seeing occurs because querySelector returns an Element type, but the style property is only available on HTMLElement. You need to cast the result to HTMLElement or use a more specific selector method.

    Here's the corrected script section:

    <script>
      // Simple accordion functionality
      document.addEventListener("DOMContentLoaded", () => {
        const accordionButtons = document.querySelectorAll(".faq-item button");
    
        accordionButtons.forEach((button) => {
          const controlId = button.getAttribute("aria-controls");
          const content = controlId ? document.getElementById(controlId) : null;
    
          button.addEventListener("click", () => {
            const expanded = button.getAttribute("aria-expanded") === "true";
            button.setAttribute("aria-expanded", (!expanded).toString());
    
            if (content) {
              content.classList.toggle("hidden");
            }
    
            // Toggle icon rotation
            const icon = button.querySelector(".faq-icon") as HTMLElement;
            if (icon) {
              icon.style.transform = expanded ? "" : "rotate(180deg)";
            }
          });
        });
      });
    </script>
    

    The key change is adding as HTMLElement after button.querySelector(".faq-icon"). This type assertion tells TypeScript that the element is an HTMLElement, which has the style property.

    Alternatively, you could use a type guard:

    const icon = button.querySelector(".faq-icon");
    if (icon instanceof HTMLElement) {
      icon.style.transform = expanded ? "" : "rotate(180deg)";
    }
    

    Both approaches will resolve the TypeScript error while maintaining the functionality of your FAQ accordion component.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.