arrow_backBACK TO DRILLS
Black Beltstate-basicsPREMIUM
TypeScript Excess Property Checking Is Bypassed Through Structural Assignment to useState
This component defines a typed form state and updates it through an intermediate variable rather than an inline literal.
REACT_MODULE // 0x42
interface UserForm {
name: string;
email: string;
}
const [form, setForm] = useState<UserForm>({ name: "", email: "" });
const payload = { name: "Alice", email: "a@x.com", role: "admin" };
setForm(payload);Why does this code compile without a TypeScript error, despite payload having a role property not present on UserForm?