cap-js / cds-types

Type definitions for CDS
Apache License 2.0
9 stars 8 forks source link

[SUGGESTION] Export interfaces instead of types to allow module augmentation #205

Open aschmidt93 opened 3 weeks ago

aschmidt93 commented 3 weeks ago

This is a generalization of #185, where it was suggested to use an interface for cds_services. I'd like to suggest to expand this approach and apply it to other types, especially inline defined, too. This allows users to use module augmentation to improve the types in their projects.

Examples:

// currently
export const connect : {
  // ...
}
// suggested
export interface Connect {
 // ...
}

export const connect : Connect;

Example for possible module augmentation:

// index.d.ts

declare module '@sap/cds' {
  export interface Connect {
   // limit datasource to services available in the project
    to( datasource : 'myServiceA' | 'myServiceB', options? : cds_connect_options) : Promise<Service>;
  }
}