admin管理员组文章数量:1356745
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
}
ponentDidMount() {
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. .js
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
}
ponentDidMount() {
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./flow-type-cheat-sheet/latest/#lib/bom.js
Share Improve this question asked Aug 18, 2017 at 9:27 Pratik BothraPratik Bothra 2,7042 gold badges33 silver badges44 bronze badges2 Answers
Reset to default 5There 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!
本文标签:
版权声明:本文标题:javascript - What is the correct flow type for window object? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743959540a2568765.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论