Error in typings
See original GitHub issue@nik0kin There seems to be an issue with the typings:
The following is allowed by the typings but results in strava
being undefined during runtime
import { strava } from 'strava-v3' //
So we tried using the default import and now strava
is defined during runtime
import * as strava from 'strava-v3' // this results in strava being defined during runtime
But the issue with that:
- there are api methods on the instance during runtime
- but during dev time there are no api methods available only
- defaults -strava
The typings suggest that strava does not use default exports, or at least in addition also exports the strava constant. Howveer that does not seem to be the case:
Looking at the js there seems to be only a single default export made, hence import { strava }
syntax does not work:
https://github.com/UnbounDev/node-strava-v3/blob/a1bfcb3664e6ef4921c8c91b7a3cd295185ce70f/index.d.ts#L158
Should be:
declare const strava : Strava;
And: https://github.com/UnbounDev/node-strava-v3/blob/a1bfcb3664e6ef4921c8c91b7a3cd295185ce70f/index.d.ts#L160 Should be
export = strava;
This is only a partial fix as this excludes all interfaces from being exported. in order for this to work add the following line at the end:
export as namespace strava;
Which allows users to access the interfaces as follows:
const routes: strava.ActivitiesRoutes
Inspiration taken from moment
:
https://github.com/moment/moment/blob/63f3d52945bc773925b862c61ee7a322d4a33308/ts3.1-typings/moment.d.ts#L784
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (6 by maintainers)
First off apologies for breaking stuff for you guys. After looking into this a bit further it seems the typing I provided are only supported by later typescript versions.
Using implicit default importing is disabled by policy (as is the default by now) in our projects, hence we could no use:
import strava from 'strava-v3'
After reverting to the previous typings + some fiddling we found the following works well:
import { default as strava, Strava} from 'strava-v3';
So for the time being I’m asking to revert back to the previous typings. By simply reverting the commit made by the PR.
That said there is an issue with the typing, since other imports are also possible but produce runtime errors like:
import * as strava from 'strava-v3'
I suggest calling out the recommended way of importing this into typescript projects on the npm page. It would be helpful to provide an sample that works across typescript versions and does not require changing compiler settings.
@nik0kin Can you check in your setup if the following provides correct typings + has the strava object populated during runtime:
import { default as strava, Strava} from 'strava-v3';
Fixed in v2.0.9, just published.