const assertion
2944 ワード
assertion?

const assertion
as const
というキーワードでタイプを断言することができます.let hello = 'world' as const
// in ts
let hello = <const>'world'
hello = 'earth' // 컴파일 타임 에러
オブジェクトのconst断言
const obj = {
hello: 'world'
}
/*
const obj = {
hello: string
}
*/
// hello만 assertion
const obj = {
hello: 'world' as const,
foo: 'bar'
}
// 모든 속성에 대해 assertion
const obj = {
hello: 'world',
foo: 'bar'
} as const

ソース
Reference
この問題について(const assertion), 我々は、より多くの情報をここで見つけました https://velog.io/@leebonggu12/const-assertionテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol