Question presented to candidate:
"You are writing a reusable PriceTag component for our shop. It needs a label, an amount, a currency from a fixed list, optional tags and an on-sale flag. How do you declare those props, how would you validate them, and what actually happens when a parent passes something invalid?"
What a strong answer should cover:
- Props are the inputs of a component: data passed down from the parent, read-only inside the child (one-way data flow).
- Declaration forms: an array of names, an object with options, or (in
<script setup>with TypeScript) a type. - Validation options:
type(constructor or array of constructors),required,default(a factory function for objects and arrays) and a customvalidator(which also receives all props since Vue 3.4). - Boolean casting: a boolean prop that is present with no value is
true, absent isfalse. - Failed validation only logs a development warning; the component still renders, and production builds skip the checks entirely.
- camelCase in JavaScript, kebab-case in templates.
Clarifying questions expected:
- "Is the project in TypeScript? Then most of this moves to compile-time types."
- "Should an invalid currency fall back to a default, or is a dev warning enough?"
Code / implementation expected: Yes. A props declaration with at least a required prop, a default and a custom validator.