// Parts copied from: // https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/tree/bd3e2a6c213932fbf0cec6befea4fb90457714ab // License: MIT. function TextInputWithFocusButton() { // initialise with null, but tell TypeScript we are looking for an HTMLInputElement const inputEl = React.useRef(null); const onButtonClick = () => { // strict null checks need us to check if inputEl and current exist. // but once current exists, it is of type HTMLInputElement, thus it // has the method focus! ✅ if (inputEl && inputEl.current) { inputEl.current.focus(); } }; return ( <> {/* in addition, inputEl only can be used with input elements. Yay! */} ); } type ButtonProps = React.ComponentProps; // no problem! grab your own! type AlertButtonProps = Omit; // modify const AlertButton: React.FC = (props) => (