When initializing a new Realtime client with an optional clientId, there’s an inconsistency between the TypeScript type definition and the runtime validation.
In TypeScript, passing clientId: null results in a compile-time error:
No overload matches this call.
Overload 1 of 2, '(options: ClientOptions<CorePlugins>): Realtime', gave the following error.
Type 'string | null' is not assignable to type 'string | undefined'.
Type 'null' is not assignable to type 'string | undefined'.
Overload 2 of 2, '(keyOrToken: string): Realtime', gave the following error.
Argument of type '{ key: string; clientId: string | null; }' is not assignable to parameter of type 'string'.
So according to the typings, only string | undefined is allowed.
However, when passing undefined instead of null, a runtime error occurs:
Error: clientId must be either a string or null
Steps to reproduce:
import { Realtime } from "ably";
const user = { id: undefined };
const realtimeClient = new Realtime({
key: 'your-ably-key',
clientId: user.id ?? undefined // ✅ Compiles, ❌ Throws runtime error
});
const realtimeClient2 = new Realtime({
key: 'your-ably-key',
clientId: user.id ?? null // ❌ TypeScript error, ✅ Works at runtime
});
Expected behavior:
- The SDK should either allow
null in TypeScript definitions (clientId?: string | null) or accept undefined at runtime without throwing an error.
Actual behavior:
- TypeScript forbids
null, but runtime requires it.
Environment:
- SDK:
ably@2.14.0
- TypeScript:
5.1.x
- Framework:
Next.js 15.5.5 (Turbopack)
- Runtime: Node.js 23.x
Suggested fix:
Update the ClientOptions type definition to allow clientId?: string | null to match runtime behavior.
┆Issue is synchronized with this Jira Task by Unito
When initializing a new
Realtimeclient with an optionalclientId, there’s an inconsistency between the TypeScript type definition and the runtime validation.In TypeScript, passing
clientId: nullresults in a compile-time error:So according to the typings, only
string | undefinedis allowed.However, when passing
undefinedinstead ofnull, a runtime error occurs:Steps to reproduce:
Expected behavior:
nullin TypeScript definitions (clientId?: string | null) or acceptundefinedat runtime without throwing an error.Actual behavior:
null, but runtime requires it.Environment:
ably@2.14.05.1.xNext.js 15.5.5 (Turbopack)Suggested fix:
Update the
ClientOptionstype definition to allowclientId?: string | nullto match runtime behavior.┆Issue is synchronized with this Jira Task by Unito