Add typed-query-selector/strict for compile-time CSS selector validation
Enables strict mode type checking for querySelector calls to catch invalid CSS selectors at compile time rather than runtime.
Changes
- Added
[email protected]as dev dependency - Imported
typed-query-selector/strictinglobal.d.tsto enable selector validation - Wrapped existing
RegExpinterface augmentation indeclare globalblock (required when file becomes a module)
Effect
Invalid selectors now produce TypeScript errors:
// Returns `never` type in strict mode - TypeScript error on usage
const el = document.querySelector('div[unclosed');
// Valid selectors get precise typing
const div = document.querySelector('div.container'); // HTMLDivElement | null
This prevents issues like malformed selectors reaching production (referenced in #120 and commit 1a04193).
Original prompt
This section details on the original issue you should resolve
<issue_title>Add
typed-query-selector/strictlocally to ensure selectors are valid</issue_title> <issue_description>https://github.com/g-plane/typed-query-selector#strict-modeThis type should make TS fail if a selector is invalid. This would avoid:
- https://github.com/refined-github/github-url-detection/pull/120#issuecomment-1177894837
- https://github.com/refined-github/github-url-detection/commit/1a04193dc4f8809329e9c448c8d05b3e8094ad6d
cc @yakov116 </issue_description>
Comments on the Issue (you are @copilot in this section)
- Fixes refined-github/github-url-detection#137
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.