Modifier properti iki ngontrol apa properti iku kudu ana lan apa bisa **diowahi-owahi".
Optional (?)
ts
{
: ;
?: ;
}
: = { : };
: = { : , : };
() {
u..;
u.?.;
}
Modifier properti iki ngontrol apa properti iku kudu ana lan apa bisa **diowahi-owahi".
?) {
: ;
?: ;
}
: = { : };
: = { : , : };
() {
u..;
u.?.;
}
Propertyti opsional nduweni tipe T | undefined, mula compiler maksa sampeyan ngopeni kasus sing ilang — nyegah bug "cannot read property of undefined".
interface Point { readonly x: number; readonly y: number; }
const p: Point = { x: 1, y: 2 };
p.x = 5; // ❌ Error: cannot assign to readonly property
// arrays too
const nums: readonly number[] = [1, 2, 3];
nums.push(4); // ❌ push doesn't exist on readonly array
readonly mung kompilasi wae (ora ana paksaan runtime), nanging iku dokumentation lan paksaan immutability ing sistem tipe, ngenteni mutasi sing accidental.
interface Config { readonly id: string; tags?: readonly string[]; }
type Frozen = Readonly<User>; // utility type makes ALL props readonly
? ndhuwe model data sing bener-bener opsional lan maksa null-safety; readonly ngandharake lan paksaan immutability (apik banget kanggo config, props, lan nyegah mutasi state sing accidental).
Rorone nedahake pengecekan kabenaran menyang compiler.