Add TypeScript support to forms
When working with form names, it’s nice to have typescript support:
interface CustomerFormType extends HTMLFormElement {
firstName: HTMLInputElement;
lastName: HTMLInputElement;
}
declare global {
interface Document {
newCustomer: CustomerFormType;
}
}
class CustomerForm extends Component {
onSubmit = (e) => {
e.preventDefault();
const firstName = document.newCustomer.firstName.value;
const lastName = document.newCustomer.lastName.value;
console.log({firstName, lastName});
};
render() {
return (
Submit
);
}
}
Tweet