2019/11/23 TIL

HANJIN·2019년 11월 24일
0

TIL

목록 보기
14/14
post-thumbnail

TypeScript Non-null assertion operator

TypeScript의 타입체커에게 null이 될 수 없다고 알려주는 표현식.

// Compiled with --strictNullChecks
function validateEntity(e?: Entity) {
    // Throw exception if e is null or invalid entity
}

function processEntity(e?: Entity) {
    validateEntity(e);
    let s = e!.name;  // Assert that e is non-null and access name
}
profile
소프트웨어 엔지니어.

0개의 댓글