How can you use a type (number) to look at the property of an object?
An array is an object, and has values at numbered keys, so ArrayType[number] would be a union of the types of each element of the array.
NonNullable<Type> Constructs a type by excluding null and undefined from Type.
Here's an example of what the data structure is expected to extend, using an arbitrary User type. You can visit the TS playground link and mouseover the lettered type names A through F to see what the IntelliSense thinks the types are:
TS Playground
type User = {
one: 'This is';
two: 'the targeted type';
};
type ApiResult = {
getUsers: {
data: Array<{
users: Array<User> | null | undefined;
}>;
};
};
declare const rowData: unknown;
const user = rowData as NonNullable<ApiResult["getUsers"]["data"][number]["users"]>[number];
// examine hierarchy:
type A = ApiResult
type B = ApiResult["getUsers"]
type C = ApiResult["getUsers"]["data"]
type D = ApiResult["getUsers"]["data"][number]
type E = ApiResult["getUsers"]["data"][number]["users"]
type F = NonNullable<ApiResult["getUsers"]["data"][number]["users"]>[number]
"getUsers"is also a type; it's a string literal type. The notationT[K]is an indexed access type whereTis an object-like type andKa keylike type assignable tokeyof T, and thenT[K]is the value types you'd get from indexing into an object of typeTwith a key of typeK. Iffoois of typeFoo, andkis of type"x", andfoo[k]is of typestring, thenFoo["x"]is of typestring.