1
我发现this文章其相当有趣,但它不帮助我,当我尝试扩展像window
这样的全局变量时。将属性添加到打字稿中的javascript对象而没有错误
Test.ts
window.test = {}; //ERROR: Property 'test' does not exist on type 'Window'.
(function (test)
{
//do stuff
} (window.test)); //Build: Property 'test' does not exist on type 'Window'
错误消息:
ERROR: Property 'test' does not exist on type 'Window'.
我该如何解决这个问题?
有没有像JS中的'interface'或它只是在打字稿? –
@MahmoudZakal'interface'是一个打字稿的东西:http://www.typescriptlang.org/docs/handbook/interfaces.html,因为在javascript中不需要这样的东西 –
截至今天,还有点儿需要在JS中执行此操作,如果您使用TS编译器使用'checkJs'选项进行类型检查。在这种情况下,编译器会抱怨'window.test = ...',但用window [“test”] = ...'可以。 – Coderer