Skip to content

Syntax

Offset access

An offset access is the type of one element of another type: the type, then the key in square brackets (T[K]).

The element under the string key offset.

T['offset']
offset
type
literal

resultTypeLang\Type\TypeOffsetAccessTypeNode

The element under a key of the type U.

T[U]
offset
type
type

resultTypeLang\Type\TypeOffsetAccessTypeNode

An element of a shape under a numeric key.

array{int, string}[0]
offset
type
fields
type
type
literal

resultTypeLang\Type\TypeOffsetAccessTypeNode

A generic with a shape as the key.

T<U>[object{key: int, ...}]
offset
type
args
type
type
fields · unsealed
field
key
type

resultTypeLang\Type\TypeOffsetAccessTypeNode

Offsets chain with each other and with the list syntax: each suffix applies to the result of the previous one.

T['a'][]['b']
offset
list
offset
type
literal
literal

resultTypeLang\Type\TypeOffsetAccessTypeNode