Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

export BaseParams #8

Merged
merged 1 commit into from
Apr 5, 2023
Merged

export BaseParams #8

merged 1 commit into from
Apr 5, 2023

Conversation

fergusean
Copy link
Contributor

Changes

In a brand new Vue/Vite-based setup, creating an API client and then exporting it for use:

import createClient from 'openapi-fetch';
import type { paths } from './openapi-types';

const { get, post, del } = createClient<paths>({
    baseUrl: 'http://localhost:3000'
});

export default { get, post, del };

TypeScript throws the following error:

Exported variable 'get' has or is using name 'BaseParams' from external module "/Users/sean/Code/sample-app/node_modules/openapi-fetch/dist/index" but cannot be named. ts(4023)

Exporting BaseParams resolves the error.

I don't appear to have the same issue with my React Native codebase, so I think it's definitely a result of a particular tsconfig - but this is a brand new Vue/Vite-based setup created with their CLI and no tsconfig overrides.

How to Review

How can a reviewer review your changes? What should be kept in mind for this review?

Checklist

  • Tests updated
  • README updated

Copy link
Owner

@drwpow drwpow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me. I’m not exactly sure why this fixes the error you’re having, but there’s no harm in export-ing types

@drwpow drwpow merged commit d55c927 into drwpow:main Apr 5, 2023
@drwpow
Copy link
Owner

drwpow commented Apr 5, 2023

- export default { get, post, del };
+ export { get, post, del };

also as a minor suggestion: exporting the individual methods is easier to consume, then you can just call import { get, post, …} rather than import client.

Or, if you always want to export the whole object, then just shorten it to export default createClient(…). No need to destructure and rebuild the object.

@fergusean
Copy link
Contributor Author

Oops -- that was an oversight in an abbreviated example. The actual code is much larger (wraps the functions for auth injection & app-specific error handling). Thanks for the tip, though! 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants