我使用--strict
编译器选项,但在访问savedEvent
时,它并未警告我可能是undefined
:
tableService.queryEntities<EventSchema>(eventTableName, query, <any> null, {autoResolveProperties: true}, (error, result, response) => {
if (error) {
context.log.error(`Attempting to remove event. Could not find event with id: ${id}. Err: `, error);
return;
}
// savedEvent can be undefined here since result.entries can be empty
let savedEvent = result.entries[0];
}
如何让它警告我?
答案 0 :(得分:0)
TypeScript assumes array access is in bounds;没有编译器选项来改变它。
--alwaysStrict
与在输出文件顶部发出"use strict";
指令有关;这不会改变类型检查。如果您正在寻找最不宽松的类型检查规则,那么您可能需要--strict
。