让TypeScript警告数组索引是否可用

时间:2018-06-18 18:27:47

标签: typescript

我使用--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];
}

如何让它警告我?

1 个答案:

答案 0 :(得分:0)

TypeScript assumes array access is in bounds;没有编译器选项来改变它。

--alwaysStrict与在输出文件顶部发出"use strict";指令有关;这不会改变类型检查。如果您正在寻找最不宽松的类型检查规则,那么您可能需要--strict