Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added TypeScript support for $.fn #424

Closed

Conversation

cyfung1031
Copy link

@cyfung1031 cyfung1031 commented May 3, 2023

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
Copy link
Author

cyfung1031 commented May 3, 2023

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.

Added TypeScript support for $.fn

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

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

The element array shall be the normal use for this script. If the array content is other type such as document, window, number, etc, for typescript users, they shall do `$(document)[0] as any as Document`.
@fabiospampinato
Copy link
Owner

  [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
Copy link
Author

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

@cyfung1031 cyfung1031 closed this May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Augmenting Cash with my own functions npm install $ not work
2 participants