在Typescript中,以下一行代码的语法会与JavaScript中的语法在语义上相等:
// Some knockout event handler
myFunc(data: string, evt: Event) {
// If enter or tab key up were detected add the excuse to the collection
if (evt.enterKey || evt.which == 9) {
// Do Something
}
}
我在这里遇到的问题是,与普通的JavaScript事件不同,TypeScript的Event类没有enterKey
或which
属性。那么我如何检测按下哪个键而不会出现TypeScript编译错误和丑陋的红色波浪线呢?