question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@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:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ntzioliscommented, Oct 17, 2020

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';

0reactions
markstoscommented, Oct 19, 2020

Fixed in v2.0.9, just published.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error in typings · Issue #158 · pmndrs/use-gesture - GitHub
Error in typings #158 ... Hey, I'm not getting that error, see below: ... to your tsconfig.json and open up types.d.ts I see...
Read more >
Typing error definition and meaning | Collins English Dictionary
Typing error definition: an error made while using a keyboard to write something | Meaning, pronunciation, translations and examples.
Read more >
visual studio / typescript typings errors - Stack Overflow
answer is: "Under the covers, we run the TypeScript compiler as a task. The command we use is: tsc -p ." I run...
Read more >
Strongly Typed Error Handling in TypeScript | by Mat Jones
Strong typing is better than weak typing. Clean, concise, and strongly typed error handling in just 46 lines of code, including the UI....
Read more >
TypeScript errors and how to fix them
Errors in catch clauses can only be typed with any or unknown . If you need a more precise error typing, you can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found