Skip to content

Add proper return type for fetchConnections method#16

Open
AlmogCohen wants to merge 1 commit intoDRFR0ST:mainfrom
AlmogCohen:feat/add-fetchconnections-type
Open

Add proper return type for fetchConnections method#16
AlmogCohen wants to merge 1 commit intoDRFR0ST:mainfrom
AlmogCohen:feat/add-fetchconnections-type

Conversation

@AlmogCohen
Copy link
Copy Markdown

Summary

Added proper TypeScript return type for the fetchConnections() method to improve type safety and developer experience.

Changes

Added LibreConnectionsResponse interface that properly types the response from the connections endpoint:

export interface LibreConnectionsResponse extends LibreResponse {
  status: number;
  data: LibreConnection[];
  ticket: Ticket;
}

Updated fetchConnections() method to use this type:

public async fetchConnections(): Promise<LibreConnectionsResponse> {
  // ... implementation
  const connections = await this._fetcher<LibreConnectionsResponse>(
    LibreLinkUpEndpoints.Connections, 
    { headers }
  );
  // ...
}

Benefits

  1. Type Safety: IDE and TypeScript can now properly infer the return type
  2. Better Autocomplete: Developers get proper suggestions when working with connections data
  3. Type Checking: Catches potential bugs at compile time
  4. Documentation: Type definition serves as inline documentation for the API response structure

Example Usage

const client = new LibreLinkClient({ email: 'user@example.com', password: 'pass' });
await client.login();

const response = await client.fetchConnections();
// response is now properly typed as LibreConnectionsResponse
// IDE knows that response.data is LibreConnection[]
const connections = response.data;
connections.forEach(conn => {
  console.log(conn.firstName, conn.lastName); // Fully typed!
});

Testing

  • ✅ All existing tests pass (12 pass, 0 fail)
  • ✅ TypeScript compilation successful
  • ✅ No breaking changes - purely additive typing

Added LibreConnectionsResponse interface to provide proper typing
for the fetchConnections() method return value.

This improves type safety and enables better IDE autocomplete when
working with connection data.

Changes:
- Added LibreConnectionsResponse interface in types.ts
- Added return type annotation to fetchConnections() method
- Added type parameter to _fetcher call for connections
- Added type assertion for cached connections

The response structure includes:
- status: number
- data: LibreConnection[] (array of all connections)
- ticket: Ticket (authentication ticket)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant