Typing

If you are using TypeScript in your project, you can leverage LiveObjects' built-in TypeScript support to ensure type safety and enable autocompletion when working with objects on a channel.

Global AblyObjectsTypes interface

You can type objects on all your channels by defining a global AblyObjectsTypes interface. If you only want to type the root object for a specific channel, see the Typing channel.objects.getRoot() section below.

Define the AblyObjectsTypes interface in a type declaration file. You can create a file named ably.config.d.ts in the root of your application:

JavaScript

This enables TypeScript to infer the correct types when accessing and mutating LiveObjects:

JavaScript

Typing channel.objects.getRoot()

You can pass a type parameter directly to the channel.objects.getRoot<T>() method call to type the root object for a channel explicitly:

JavaScript

Typing channel.objects.getRoot<T>() is particularly useful when your application uses multiple channels, each with a different object structure.

Select...