What <ShippingFormInputs> actually does
useForm<ShippingFormInputs>()
This is NOT runtime code.
It only tells TypeScript:
“This form should only accept fields defined in ShippingFormInputs.”
📦 Example type
type ShippingFormInputs = {
email: string;
age: number;
};
So valid fields are only:
-
"email" -
"age"
❌ How it catches typos
Example mistake:
register("emial"); // ❌ typo
👉 TypeScript immediately checks:
“Is 'emial' a key in ShippingFormInputs?”
Answer:
- ❌ NO
So it shows error:
Argument of type '"emial"' is not assignable to parameter of type '"email" | "age"'
Comments
Post a Comment