Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Typescript import doesn't work. #132

Closed
ashok-sc opened this issue Nov 4, 2017 · 15 comments
Closed

Typescript import doesn't work. #132

ashok-sc opened this issue Nov 4, 2017 · 15 comments

Comments

@ashok-sc
Copy link

ashok-sc commented Nov 4, 2017

When importing Analytics using Typescript:
import Analytics from 'analytics-node';

I get the following error:

node_modules/@types/analytics-node/index"' has no default export.

I can revert to this const Analytics = require('analytics-node');, but I should be able to do this with Typescript imports right?

As you can see above, I do have the type definitions installed as well.

@f2prateek
Copy link
Contributor

I'm not that familiar with typescript, but looking at microsoft/TypeScript#3337 (comment); did you try this?

import * as analytics from 'analytics-node';

@ashok-sc
Copy link
Author

ashok-sc commented Nov 4, 2017

When I use that type of import I get the following error:
resolves to a non-module entity and cannot be imported using this construct.

Removing the type definitions completely fixes this problem. This is unfortunate :(.

@stephenmathieson
Copy link
Contributor

I'm not too sure how TypeScript works, but how is it expecting us to export the Analytics class?

I think this may be an issue with @types/analytics-node btw.

@lev-kuznetsov
Copy link

Looking at https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/analytics-node/index.d.ts I think you're supposed to import like this:

import {Analytics} from 'analytics-node'

@f2prateek
Copy link
Contributor

hey @ashok-sc , could you try @lev-kuznetsov 's suggestion? Closing this issue for now, but please re-open if it's still an issue.

@havenchyk
Copy link

@f2prateek it's definitely not working and issue need to be reopened

@JQuezada0
Copy link

This should be reopened. This is still an issue.

@f2prateek
Copy link
Contributor

I don't think this is the right place for the issue- the issue is from wherever your analytics-node types are being defined, which is outside of this repostiroty, e.g. https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/analytics-node/index.d.ts. You should open this issue for whichever library is the one you're using to package the TypeScript information.

@ajsharp
Copy link

ajsharp commented Apr 9, 2018

@f2prateek Some packages declare their own types inside the home repo. +1 for doing that here

@f2prateek
Copy link
Contributor

@ajsharp seems reasonable - I closed the issue because the original post was reporting a bug in a different package. Feel free to open a new issue if you'd like to request TypeScript support natively in this package. I'm not sure if we'll add it soon, but it would serve as a good forum for people to track the issue and show their interest.

@stephenmathieson
Copy link
Contributor

IMO, since Segment doesn't use TypeScript here, the definitions don't really belong here either. Putting them in this repository is just putting additional maintenance on the Segment team that isn't completely necessary, since the @DefinitelyTyped org exists.

@RXminuS
Copy link

RXminuS commented Jul 3, 2018

I'm sorry @stephenmathieson that is such a bad argument. It's like saying that the Docs should live in a different repo because you only ever look at the code internally anyways. Any other language then Javascript you would have had to type your classes, only in JS world does it suddenly become a "strain on the team to maintain".

That's what open source is for, I would be more then happy to have made a PR here to fix the issue but adding the Type definitions to this repo at least shows that you care about the developers that use this library.

Now I wouldn't have even commented if this was a community driven project, (although I would have proposed including the TS anyways) but you are a developer-focussed for profit business, so I feel a response like, "we're not going to help because the typings aren't part of this repo" is a bit rude.

@RXminuS
Copy link

RXminuS commented Jul 3, 2018

BTW, this is the solution DefinitelyTyped/DefinitelyTyped#23760

@stephenmathieson
Copy link
Contributor

It's like saying that the Docs should live in a different repo because you only ever look at the code internally anyways.

It's nothing like that. TypeScript is not JavaScript, so the JavaScript developers that maintain this project are going to do a bad job at maintaining the TS definitions. Just because you decided to learn TypeScript does not mean Segment's JS devs have. When I was still there, there were literally no TypeScript projects in the entire segmentio org (1000s of repos). We didn't use TS at all, so we'd do a horrible job of maintaining definitions for it. This is exactly why the DefinitelyTyped organization exists.

@havenchyk
Copy link

@RXminuS so, does it mean that solution is to use esModuleInterop flag?

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

No branches or pull requests

8 participants