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

Vscode don't show hints / autocomplette in JavaScript addEventListener witch querySelector #52108

Closed
bzag44 opened this issue Dec 28, 2022 · 8 comments
Labels
Duplicate An existing issue was already created

Comments

@bzag44
Copy link

bzag44 commented Dec 28, 2022

Type: VSCode autocomplette

When I use (Windows and Linux)
addEventListener with document.querySelector('#id')

addEventListener doesn't show event hints, but with
document.getElementById('id') it works fine. Can it be fixed?

I would like to use document.querySelector('#id')
instead getElementById('id')

VS Code version: Code 1.74.2 (e8a3071ea4344d9d48ef8a4df2c097372b0c5161, 2022-12-20T10:27:19.253Z)
OS version: Linux x64 5.4.0-135-generic
Modes:
Sandboxed: No

Extensions (9)
Extension Author (truncated) Version
vscode-intelephense-client bme 1.8.2
simple-react-snippets bur 1.2.7
prettier-vscode esb 9.10.3
live-sass gle 5.5.1
vscode-language-pack-pl MS- 1.74.12140928
material-icon-theme PKi 4.23.1
LiveServer rit 5.7.9
sass-indented syl 1.8.23
JavaScriptSnippets xab 1.8.0
@bzag44
Copy link
Author

bzag44 commented Dec 28, 2022

gs2
gs

@bzag44 bzag44 changed the title Vscode don't show hints in JavaScript addEventListener witch querySelector Vscode don't show hints / autocomplette in JavaScript addEventListener witch querySelector Dec 28, 2022
@ArturoDent
Copy link

See, for example, https://stackoverflow.com/a/64732930/836330. Probably same thing.

@bzag44
Copy link
Author

bzag44 commented Dec 29, 2022

See, for example, https://stackoverflow.com/a/64732930/836330. Probably same thing.

I saw this thread (and others) unfortunately not, thanks

@mjbvz mjbvz transferred this issue from microsoft/vscode Jan 4, 2023
@mjbvz
Copy link
Contributor

mjbvz commented Jan 4, 2023

Moving to TS since this looks like an inconsistency with the DOM typings

getElementByIdreturns an HTMLElement which has an addEventListener method.

Meanwhile querySelector returns an Element, which is usually but not always an HTMLElement. Element does not have to have a addEventListener method


@bzag44 You can fix your example by adding the same instanceof check as https://stackoverflow.com/a/64732930/836330

@mjbvz mjbvz removed their assignment Jan 4, 2023
@RyanCavanaugh
Copy link
Member

Duplicate #19549 / #4689 / #10924

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 5, 2023
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@legendaryruhl
Copy link

Try changing your constant or variable name. For me it works.

@bzag44
Copy link
Author

bzag44 commented Mar 24, 2023

Try changing your constant or variable name. For me it works.

thanks, it's a wrong way, (I think)
I don’t know but after vsc code update worked,
now after another update.... don't work again...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

6 participants