-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
window.PointerEvent is undefined #18756
Comments
|
Global declarations are not all mirrored on interface Window {
PointerEvent : typeof PointerEvent ;
} |
@mhegazy I had tried that before opening this issue, and it didn't work for me either. Still, checking for a property on window is a very common way to do feature detection. It should be handled correctly by TypeScript. For instance, Google, Microsoft, and the W3C all recommend |
looking at other issues seems we have been inconsistent here. some we did add and some we did not.. here are some: it is possible we keep adding one off, or we need to have a more general solution. #14052 seems like a prerequisite to correctly model global polluter in JS |
That absolutely should work. I've done it numerous times and it has always worked. are you sure the file containing the declaration is part of your compilation context? |
It's not working there because you're trying to augment (p.s. yes it's subtle, I'm sorry about that 😕) |
I think I'm just going to use If I was trying to use This code is going into a library, so global side effects are probably not great, but neither are type errors. |
If you are writing a module then you need to use declare global {
interface Window {
PointerEvent: typeof PointerEvent;
}
} which augments the type of the global If you are writing a module and you do not write the |
Closing as a duplicate of #14052. |
I'd recommend declaring it exactly as if the generator script emits it so that you don't get duplicate declaration errors down the line. |
TypeScript Version: 2.4.1
Code
Expected behavior:
This should work. It is a valid feature detection test.
Actual behavior:
Notes
It appears that
PointerEvent
is defined ondom.generated.d.ts
withdeclare var PointerEvent
. ShouldWindow
be augmented with that type, or is there a more idiomatic way to check for the presence of a global definition in TypeScript?The text was updated successfully, but these errors were encountered: