Loading topic
? and readonly to these shapes, so the rules here5 min read? on a property changes the type of an object, how that differs from a property typed T | undefined, and which mistakes come up most often. It assumes you know basic TypeScript syntax, interfaces and type aliases, and union types including undefined. It also assumes y5 min read?.), and nullish coalescing (??). It also covers the mistakes that come up most of5 min readstring | undefined, and you have strict mode (specifically strictNullChecks) turned on. Earlier chapters showed how ? marks a property as optional and how to read optional values safely6 min readreadonly modifier on object properties: how to declare it, what the compiler rejects, and how to update data you have locked. It assumes you know interfaces, type aliases, and optional properties (?). Later chapters cover its limits (shallow, compile-time only), arrays, c5 min readreadonly modifier on a property, and you are comfortable with JavaScript objects and arrays. Earlier chapters showed that readonly blocks reassignment. This chapter covers two limits on that protection.6 min readreadonly and ? are declared. You should also know that readonly is shallow and that it exists only at compile time. Here we look at one consequence of that design: a readonly property does not stop a value from b6 min readreadonly applies to arrays and tuples. It assumes you know basic TypeScript syntax, interfaces and type aliases, union types including undefined, and how JavaScript arrays behave. It builds on the earlier chapters showing that a readonly property is shallow and exists o6 min readreadonly on interface properties and the shallow nature of readonly from earlier chapters. Here we apply readonly to class fields, which have a few rules and edge cases of their own.5 min read?) or readonly property. It also assumes you know that an optional property has the type T | undefined when you read it. If those ideas are new, review the earlier chapters on optional and readonly properties first.6 min readreadonly properties, and the readonly T[] array type from the earlier chapters. It builds on the point that readonly is shallow and exists only at compile time.5 min readReadonly<T> locks only the top level of an object type. This chapter builds a recursive DeepReadonly<T> that locks every level, explains each part of its definition, and covers where it stops working. It also shows how to make the runtime behave the way the type claims.5 min read