Skip to content
This repository was archived by the owner on Oct 21, 2021. It is now read-only.

Commit f57709d

Browse files
committed
Fix the typescript typings
- fix type for namedItem to be consistent with the flow types. The generic type applies to the return type, not to the form - add support for refining the return type based on the constructor being passed as last argument, as done in flow types - add testing of the typings, by running the typescript compiler on the test.ts file and ensuring that it does not complain about types. The refined return type is also now covered by this test.ts file.
1 parent 98aeb95 commit f57709d

File tree

4 files changed

+200
-52
lines changed

4 files changed

+200
-52
lines changed

index.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
export type Queryable = Document | DocumentFragment | Element;
22

3-
export function closest<T extends Element = HTMLElement>(context: Queryable, selectors: string, klass?: any): T;
3+
export function closest<T extends Element = HTMLElement>(context: Queryable, selectors: string, klass?: new() => T): T;
44

5-
export function query<T extends Element = HTMLElement>(context: Queryable, selectors: string, klass?: any): T;
5+
export function query<T extends Element = HTMLElement>(context: Queryable, selectors: string, klass?: new() => T): T;
66

7-
export function querySelectorAll<T extends Element = HTMLElement>(context: Queryable, selectors: string, klass?: any): Array<T>;
7+
export function querySelectorAll<T extends Element = HTMLElement>(context: Queryable, selectors: string, klass?: new() => T): Array<T>;
88

9-
export function namedItem<T extends HTMLFormElement = HTMLFormElement>(form: T, itemName: string, klass?: any): RadioNodeList | Element;
9+
export function namedItem<T extends Element | RadioNodeList = HTMLInputElement>(form: HTMLFormElement, itemName: string, klass?: new() => T): T;
1010

1111
export function getAttribute(element: Element, attributeName: string): string;

0 commit comments

Comments
 (0)