In typescript, I made the following utility functions as shorthands for the native API.…
- User
In typescript, I made the following utility functions as shorthands for the native API. How can I improve their typing?
codetype SelectorRoot = Document | HTMLElement; function $<K extends keyof HTMLElementTagNameMap>(selector: K, root?: SelectorRoot): HTMLElementTagNameMap[K] | null; function $<T extends HTMLElement>(selector: string, root?: SelectorRoot): T | null; function $(selector: string, root: SelectorRoot = document): HTMLElement | null { return root.querySelector(selector); } function $$<K extends keyof HTMLElementTagNameMap>(selector: K, root?: SelectorRoot): NodeListOf<HTMLElementTagNameMap[K]>; function $$<T extends HTMLElement>(selector: string, root?: SelectorRoot): NodeListOf<T>; function $$(selector: string, root: SelectorRoot = document): NodeListOf<HTMLElement> { return root.querySelectorAll(selector); } function create<K extends keyof HTMLElementTagNameMap>(ele: K): HTMLElementTagNameMap[K]; function create<T extends HTMLElement>(ele: string): T; function create(ele: string): HTMLElement { return document.createElement(ele); }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.