Skip to content

How should we organize API type definitions in TypeScript? #875

Closed Answered by seancolsen
seancolsen asked this question in Developer Q&A
Discussion options

You must be logged in to vote

PascalCasePascalCase types

  • mathesar_ui/src/api/tables/constraints.d.ts

    export interface GetResponse {
      // ...
    }
  • mathesar_ui/src/api/index.ts

    export type {
      GetResponse as APITablesConstraintsGetResponse,
    } from './tables/constraints';
  • In a consuming file

    import type { APITablesConstraintsGetResponse } from '@mathesar/api';
    
    function foo(): APITablesConstraintsGetResponse {
      // ...
    }

Benefits

  • All names are still in PascalCase

Drawbacks

  • Potential for naming collisions with /endpoint/foo/ and /endpoint-foo/

Replies: 4 comments 7 replies

Comment options

seancolsen
Dec 8, 2021
Maintainer Author

You must be logged in to vote
4 replies
@silentninja
Comment options

@silentninja
Comment options

@seancolsen
Comment options

seancolsen Dec 9, 2021
Maintainer Author

@pavish
Comment options

Comment options

seancolsen
Dec 8, 2021
Maintainer Author

You must be logged in to vote
0 replies
Comment options

seancolsen
Dec 8, 2021
Maintainer Author

You must be logged in to vote
1 reply
@seancolsen
Comment options

seancolsen Dec 8, 2021
Maintainer Author

Comment options

seancolsen
Dec 8, 2021
Maintainer Author

You must be logged in to vote
2 replies
@seancolsen
Comment options

seancolsen Dec 22, 2021
Maintainer Author

@silentninja
Comment options

Answer selected by seancolsen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants