Skip to content

Export TypeScript types from package #1673

@sgoll

Description

@sgoll

For the recent version 4, the redis package includes TypeScript types but so far only the signatures of createClient(), commandOptions(), and createCluster() are exported (i.e. exported explicitly by name).

This makes it more difficult than necessary to use objects of the "public" types in custom code, such as:

class SomeClass {
  // Unable to declare this attribute:
  private redisClient: RedisClientType;
}

One workaround is to infer the types from the exported signatures:

// You _can_ get the type like this but this is hard to do for all types:
type RedisClientType = typeof redis.createClient extends () => infer ResultType
  ? ResultType
  : never;

I would suggest that index.ts should include at least exports of the most common types such as RedisClientType, RedisClientOptions, RedisClusterType, RedisClusterOptions, TuplesObject, option types for commands etc.

The only downside to this is that these types now form the public interface of the package API, i.e. may introduce breaking changes if later removed or renamed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions