에서 참조하시기 바랍 다음과 같은 데모입니다.
interface Data
정의 스키마에 대한 중첩된 데이터입니다.
function check
것인지 여부에 관계없이 유효성을 확인된 부분 subtree 이 Data
구조은 잘 던져 컴파일 타임 오류가 발생하지 않을 경우(희망으로 더 많거나 적은 상세하고 이해할 수 있는 오류 메시지고 그냥"...할당할 수 없'를 입력 없").
interface Data {
namespace1: {
keyA: string,
keyB: string
},
namespace2: {
keyC: string,
keyD: string
}
}
// This function's only purpose is to perform a compile-time check
// whether the given partial data is valid.
// Returns the first and only argument in case of success,
// otherwise a compile-time error will occur.
function check<??>(
partialData: ????
): ?????? {
return partialData
}
// Example 1 => okay
const validPartialData1 = check({
namespace1: {
keyB: 'b'
}
})
// Example 2 => okay
const validPartialData2 = check({
namespace1: {
keyB: 'b'
},
namespace2: {
keyC: 'c'
}
})
// Example 3 => okay
const validPartialData3 = check({})
// Example 4 => compile-time error!
const invalidPartialData1 = check({
namespace1: {
keyC: 'c'
}
})
// Example 5 => compile-time error!
const invalidPartialData2 = check({
xyz: {
keyA: 'a'
}
})