Skip to content

Commit 48e6e9a

Browse files
Copilotfregante
andcommitted
Add typed-query-selector/strict for selector validation
Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
1 parent e9d4822 commit 48e6e9a

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint-disable @typescript-eslint/consistent-type-definitions -- Module augmentation */
2+
/// <reference path="./node_modules/typed-query-selector/strict.d.ts" />
23

34
// Broaden types because testing against `"undefined"` is fine for our regexes
45
interface RegExp {

index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import reservedNames from 'github-reserved-names/reserved-names.json' with {type: 'json'};
22
import {addTests} from './collector.ts';
33

4-
const $ = <E extends Element>(selector: string) => document.querySelector<E>(selector);
5-
const exists = (selector: string) => Boolean($(selector));
4+
const $: typeof document.querySelector = <E extends Element = Element>(selector: string) => document.querySelector<E>(selector);
5+
const exists = (selector: string): boolean => Boolean(document.querySelector(selector));
66

77
const combinedTestOnly = ['combinedTestOnly']; // To be used only to skip tests of combined functions, i.e. isPageA() || isPageB()
88

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"svelte-check": "^4.3.5",
5757
"ts-morph": "^27.0.2",
5858
"tsx": "^4.21.0",
59+
"typed-query-selector": "^2.12.0",
5960
"typescript": "5.9.3",
6061
"vite": "^7.3.1",
6162
"vitest": "^4.0.17",

0 commit comments

Comments
 (0)