fabiospampinato / cash

An absurdly small jQuery alternative for modern browsers.
MIT License
6.51k stars 266 forks source link

Added TypeScript support for $.fn #424

Closed cyfung1031 closed 1 year ago

cyfung1031 commented 1 year ago

resolves #380; resolves #421

[key: string]: Function; is added to Cash such that #380 can be resolved.

ArrayLike<HTMLElement> is also added such that Cash can be array-like with HTMLElement results from querySelectorAll.

Screen Shot 2023-05-03 at 17 46 01 Screen Shot 2023-05-03 at 17 47 06
cyfung1031 commented 1 year ago

Note: Although $(document) $(window) might be also possible usages for $(...), but in such a case, it would not used with array-like methods. (e.g. $(document).ready(...) )

In such a rare case, the TypeScript users shall do $(document)[0] as any as Document.

fabiospampinato commented 1 year ago
  [key: string]: Function;

This seems just incorrect, so I don't think it belongs.

class Cash implements ArrayLike<HTMLElement> {

This is I guess kinda true, except maybe we should use EleLoose rather than HTMLElement, but the Cash class isn't really meant to be exposed to the user, so what benefit would this change get us?

cyfung1031 commented 1 year ago

PR closed as the change should be in Interface Cash not class Cash. And [index: number]: EleLoose | undefined already exists in types.ts And Extending Cash shall be preferred as the number index will collide with the string key