I need to pass in window from the root of my application, and I'm confused as to what flow type I should be using.
I tried
export default class ListAttribute extends Component {
props: {
frameWindow: mixed
}
componentDidMount() {
this.props.frameWindow.addEventListener('click', this.closeList, false)
}
....
}
This gives me call of method addEventListener. Method cannot be called on mixed
, I tried refinement to no luck.
I tried looking here, but couldn't find anything for the bom itself. https://www.saltycrane.com/flow-type-cheat-sheet/latest/#lib/bom.js
There currently isn't any typings for the window
object it seems. For now, it looks like the type of any
is used.
Do you need any methods that are specific to window
? If all you're doing is the one call to addEventListener
, then that can be called on any EventTarget
, which window
certainly is. And since the default type for window
is any
, you should be able to pass it in for an EventTarget
.
Here's a simpler example that hopefully shows that idea, without bringing in all the details of your code:
function withWindow(window: EventTarget) {
window.addEventListener("click", (e: MouseEvent) => console.log(e), false);
}
withWindow(window); // type checks fine!
Hope that helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With