what3words / w3w-node-wrapper

Node wrapper for the What3Words API
https://docs.what3words.com/api/v3/
MIT License
45 stars 10 forks source link

Transport is neither string nor function #51

Closed esride-nik closed 2 years ago

esride-nik commented 2 years ago

Hi,

const transport: 'axios' | 'fetch' = 'fetch';
const w3wService: What3wordsService = what3words(apiKey, config, { transport });

This is not working. I'm getting the compiler error "Type 'string' is not assignable to type 'Transport'." Ignoring this, I get a runtime error "this.transport is not a function".

I came across this solution by chance:

import what3words, { ApiVersion, What3wordsService, LocationGeoJsonResponse, LocationJsonResponse, axiosTransport } from '@what3words/api'
[...]
w3wService = what3words(<API_KEY>, config, { transport: axiosTransport() })

This works for me. Could you please explain if I'm missing someting or otherwise update your documentation?

Thanks, Nik

c5haw commented 2 years ago

Hi @esride-nik,

We recently made an update to the node-wrapper that means you now need to import the transport you'd like to use and pass that in explicitly. This resolved a previous issue which caused the project consuming the library to have to install all peer dependencies, and not just the dependency for the transport you wish to use.

The solution you have highlighted is the correct solution now and I can see our README is outdated. I have opened an issue to resolve and update our documentation so that this is explicit.

Thanks for pointing this out.

esride-nik commented 2 years ago

Hi @c5haw , you're welcome! These docs seem to be mirrored to the official w3w page, only this version differs slightly in terms of installing peer dependencies. It might be a good idea to keep the one on GitHub up to date and reference it from the official page instead of copying the text. Cheers, Nik