Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexported interface types #67

Open
mgoshorn opened this issue Nov 17, 2023 · 1 comment · May be fixed by #76
Open

Unexported interface types #67

mgoshorn opened this issue Nov 17, 2023 · 1 comment · May be fixed by #76

Comments

@mgoshorn
Copy link

Hello!

Working on an integration with the vezgo-sdk (currently v1.1.0) on a TypeScript project. Running into a bit of frustration as, although the types used by the sdk are defined, they are not exported so they cannot be imported and easily re-utilized by integrating software. For instance, a simple utility function like this:

export function initializeVezgo() {
  const clientId = process.env['VEZGO_CLIENT_ID']!;
  const secret = process.env['VEZGO_SECRET']!;
  return Vezgo.init({
    clientId,
    secret,
  });
}

Produces this error:

Return type of exported function has or is using name 'APIInterface' from external module ".../node_modules/vezgo-sdk-js/lib/vezgo" but cannot be named.ts(4058)
function initializeVezgo(): APIInterface

This is because the typescript compiler needs to provide type information about the return value of the function initializeVezgo to consumers of that function, but the type (APIInterface) is not exported by the vezgo sdk, so it cannot be utilized by the compiler. Currently, we're able to work around this by re-declaring local types from the output types using TypeScript utility functions (example below), but this rather clunky.

Example of how we're able to create workable types:

export type VezgoAPIInterface = ReturnType<typeof Vezgo.init>;
export type VezgoAPIUserInterface = ReturnType<VezgoAPIInterface['login']>;
export type VezgoAPIUserAccounts = VezgoAPIUserInterface['accounts'];
export type VezgoAccount = Exclude<
  ReturnType<Awaited<ReturnType<VezgoAPIUserAccounts['getList']>>['at']>,
  undefined
>;

// Declaration valid using re-declared type as return value
export function initializeVezgo(): VezgoAPIInterface {
  const clientId = process.env['VEZGO_CLIENT_ID']!;
  const secret = process.env['VEZGO_SECRET']!;
  return Vezgo.init({
    clientId,
    secret,
  });
}

It would be a lot simpler if the interfaces defined in index.d.ts were exported so that consumers of the sdk could directly reference the types declared there. If this change is desirable for the maintainers, I would be happy to provide a PR for it.

@matpb
Copy link

matpb commented Feb 14, 2024

I'd also highly recommend exporting the library types. While type inference by default is not bad, it is not enough.

@zcuric zcuric linked a pull request Jun 4, 2024 that will close this issue
3 tasks
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 a pull request may close this issue.

2 participants