简体   繁体   English

指定一个类型应该来自哪个环境 `lib`

[英]Specify which ambient `lib` a type should come from

I'm using window.onmessage in TypeScript. VS Code seems to think that the parameter has the type MessageEvent from lib.dom.iterable.d.ts while it should have the type MessageEvent from lib.dom.d.ts .我在 TypeScript 中使用window.onmessage Code 似乎认为该参数具有来自lib.dom.iterable.d.tsMessageEvent类型,而它应该具有来自lib.dom.d.tsMessageEvent类型。 How can I point the compiler/language service to the correct type?如何将编译器/语言服务指向正确的类型?

MessageEvent is an interface, so TypeScript merges its different definitions. MessageEvent是一个接口,所以 TypeScript 合并了它的不同定义。 It just happens that VS Code is pointing you to lib.dom.iterable.d.ts , but in reality any value of type MessageEvent you come across should implement the contract defined in lib.dom.d.ts . VS Code 恰好将您指向lib.dom.iterable.d.ts ,但实际上您遇到的任何MessageEvent类型的值都应该实现lib.dom.d.ts中定义的契约。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM