-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
MutationObserver API declarations missing #11305
Comments
|
@aluanhaddad This has nothing to do with |
@AvraamMavridis thanks for correcting me. |
@AvraamMavridis changes to the DOM part of the They do appear to be declared though in the global interfaces and all the examples on MDN demonstrate it that way. So your detection might be better if you just did something like this: if (window && MutationObserver) {
const mo = new MutationObserver();
} You will find that they are properly typed that way. |
@kitsonk Thx a lot. I will give it a try later and if works I will close the issue. |
Hi,
note that this can throw a if (typeof MutationObserver != "undefined") {
const mo = new MutationObserver();
} |
@kpreisser what you described is "feature detection" and has nothing to do with Typescript and the issue above (missing declarations), and it will probably throw Error even in a non strict mode. |
That's correct. However in your original example, you used But as @kitsonk noted, you should use the global To correctly feature-detect it, you can use |
thanks @kpreisser |
The MutationObserver related declarations are missing from the
lib.d.ts
file. Since this API is not browser specific I would expect the declarations to exist (as it happens with FileReader for example).TypeScript Version: 2.0.3
Code
Expected behavior:
To not arise an error.
Actual behavior:
Error : Property
MutationObserver
does not exist on typeWindow
I "solved" it by using the
window["MutationObserver"]
syntax. If that is an actual bug/issue I can provide a PR.The text was updated successfully, but these errors were encountered: