Question presented to candidate:
"In a <script setup> component I need to set inheritAttrs: false, give the component a name, and document which slots it accepts and what each slot receives. How do defineOptions() and defineSlots() help, and what are their limits?"
What a strong answer should cover:
- Both are compiler macros (Vue 3.3+): no import, compiled away, usable only in
<script setup>. defineOptions({...})declares component options that have no macro of their own, mainlynameandinheritAttrs; it is hoisted out ofsetup().- It rejects
props,emits,exposeandslots(use the dedicated macros), rejects type arguments, and cannot reference local variables other than literal constants. defineSlots<{...}>()is type-only: it describes each slot and its props for the IDE andvue-tsc, and returns the same object asuseSlots().defineSlotschecks both sides: the props the component passes to<slot>and the destructured slot props in the parent.- Before 3.3 the same needed a second plain
<script>block for options, or no slot typing at all.
Clarifying questions expected:
- "Which Vue version is the project on? Both macros need 3.3 or later."
- "Is the goal type safety in the editor, or runtime behaviour?
defineSlotsonly affects types."
Code / implementation expected: Optional β a component using both macros, ideally with a slot prop type error shown by vue-tsc.