How to determine the type of element returned by querySelector in TypeScript?

defines a tool function that is expected to be used to select different elements. It infers that the return type is Element, but this is a base class, and the methods and properties of many specific classes cannot be prompted automatically.

export const $ = (selector, scope = document): HTMLElement | HTMLInputElement => scope.querySelector(selector);

excuse me, how should I define this return value type so that I can indicate the specific properties and methods it has according to different elements? Thank you < 3

May.07,2021

this can only be prompted manually by you, ts

  

you can use
const input = document.querySelector < HTMLInputElement > ('input')

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e54e20-66c8c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e54e20-66c8c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?