New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Are there types available? #12
Comments
Hey @katsar0v. Thanks for the feedback & issue. Most of the interfaces are typed via JS doc inside of the core module https://github.com/DavidWells/analytics/blob/master/packages/analytics-core/src/index.js#L117-L123 From my (limited) understanding of typescript those should work? Ref What happens when you try to use this in typescript right now? |
Hi @DavidWells , unfortunatelly this are only comments which the typescript interpreter cannot read, the following does not work:
However I managed to run the script unter typescript, quite hacky, but it works
Of course, no type checking is possible with this. |
Hey @katsar0v What's the best way to support typescript types with the project? I'm keen to help but also worried about adding additional complexity + maintenance. How are other libraries handling this? |
I guess we need an npm package with just type descriptions, as you can see I created really basic and abstract interface for the listener:
I guess we just need two files:
The usage and injection in the dom would still remain via html (am not really sure how this would happen here). The other (and better) possibility is to have a full npm package, where you just import (like for node.js) so it could work just using:
I am happy to contribute to this project, I just cannot spend really much time, but am happy to answer any question. A good example to start is |
FYI here's an incomplete typings file I created for my own purposes https://gist.github.com/tommedema/b1e51013f709e42e1fb577b5d537a377 Very incomplete because I don't need most options like callbacks etc |
This is what I get when using |
It’s intended to work 😅 Do you see what is wrong in that types.d.ts file? |
Well removing all exports and leaving |
The types are generated here: https://github.com/DavidWells/analytics/blob/master/packages/analytics-core/package.json#L47 and then the final output goes through https://github.com/DavidWells/analytics/blob/master/packages/analytics-core/scripts/types.js I'm working on streamlining this for all packages and hopefully can get correct types for everything. I have a project with the types file @katsar0v where are you seeing the error? In editor or on TS compile? Thanks for reporting this
|
What is the proper way to type these other named exports? https://github.com/DavidWells/analytics/blob/master/packages/analytics-core/scripts/types.js#L15-L19 I added those (via trial/error) in VScode verifying stuff working over on that front. I might be missing something tho. |
My editor says that |
Here is my
|
what is the best way to help on this? |
@DavidWells if I put the output you have above at |
Thanks, @chrisdrackett! This will work great on the core API! Adding some additional context on where I got stuck with this last time I tried implementing typescript across the board for all plugins. Certain plugins run in So in the browser code, we do: import googleAnalytics from '@analytics/google-analytics' And in node.js we do the same: import googleAnalytics from '@analytics/google-analytics' Here is the tricky part where I'm stumped: This particular plugin (and likely many others) have a different set of initialization parameters that need to be typed separately. The browser config and the server config are different. From what I can tell, Typescript cannot infer the correct types if the same import path is used. I tried using "references" to no avail https://twitter.com/DavidWells/status/1180349883368247297 & naming the type to their output didn't work either. Is there a way to solve this problem and have types for both client AND serverside code in the same module? Or is the only way building to 2 separate module paths and requiring users to know which to import? E.g. import googleAnalytics from '@analytics/google-analytics' // client side import googleAnalytics from '@analytics/server/google-analytics' // node side
// This to me is ugly 😅 Reference links: |
@DavidWells my first thought would be to type these as the full set but note in the docs ("node.js only" or "browser only") values that only work or are used on a single platform. You could then potentially also throw if a server config value is sent to the browser code. This isn't 100% ideal, but IMO its better than having two separate modules. I'll keep thinking on it! |
Have yall @DavidWells @chrisdrackett gotten anywhere with this? There's quite a few missing bits of type that makes these libraries a bit of a headache to use with strict typescript. I'm happy to start putting types into DefinitelyTyped but, considering you're only missing pieces of types that needs a build solution, it's awkward to throw in types for your packages in there. |
I don't use this package anymore, so I'm sorry to say I can't be much help! |
Hello guys! I am trying to use this analytics script in an existing typescript environment. I tested the vanilla js and it worked pretty well, now I'd like to integrate the tool in my existing typescript application.
My question is: are there any types available or is there documentation available for using this with TypeScript?
PS: I tried searching in the available documentation in github as well for existing types in npm / TypeSearch, nothing there.
The text was updated successfully, but these errors were encountered: