-
Notifications
You must be signed in to change notification settings - Fork 631
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
Typescript support #42
Comments
Basically, the TypeScript definition of |
Any progress on this? |
This worked!! |
As this library wraps the API in own functions one cannot use the definitions from I started to write definitions for this wrapper which I use in my application. Currently only the @stephenmcd If you are willing to integrate them in the package, feel free to copy my gist. Or maybe link them in the ReadMe.md? |
Hi!
<script async defer type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=****"></script> However, It isn't recognized while running my unit tests (karma + jasmine) with Angular CLI. Any help? |
@merlosy There is a tsconfig.spec.json, maybe you need to add |
Hi @hnrchrdl , I did add it to my tsconfig.spec.json: {
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/spec",
"module": "commonjs",
"target": "es5",
"baseUrl": "",
"types": [
"jasmine",
"node",
"googlemaps"
]
},
"files": [
"test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
} And also randomly on reload I get a "google is not defined" |
@merlosy 'google is not defined' could occur if you try to use access it before the dom is ready, especially when it happens randomly. Another possibility is browser addons (adblocker or something similar) are blocking scripts. |
In order to use the existing typings from @types/googlemaps I did the following in typescript:
This then allowed me to use the google.maps namespace along with making the createClient call.
Be warned that this project and the typings project have discrepancies as well. For example the GeocoderRequest object from the typings project has a different object structure. |
@dennypc I tried your solution: import * as googleMaps from '@google/maps';
import { } from '@types/googlemaps'; but I kept receiving this tslint error:
how can I fix this? |
The scoped package of typescript is required to be named as |
Hi guys, node.js and typescript user here. I am totally befuddled by the following: Am I right in assuming that there are two competing and presumably incompatible javascript apis, one with typescript support and one without, and that I need to combine the two somehow. I am used to npm install-ing a module and its @types counterpart and then just importing the module. However, if I just try to "import * as gmaps from 'googlemaps'" then I get:
And finally what on earth does "import {} from x" even do? I cannot find that syntax anywhere. I would be really grateful for a pointer, because I feel like I am the only one in this film without a script at the moment. |
FYI, definitely typed now supports publishing types for scoped packages, so this should be possible |
@ethanresnick I've tried adding
and my entire project just breaks. Doing
VSCode has a minor note on it saying
|
No, I just forgot about it. Revisiting the topic again now I thought to check what the transpiler emitted: nothing. So I am guessing it is some way of importing type information for the transpiler without influencing the emitted output. Typescript is pretty well established and gives me immense value every day but still seems to have some dusty corners. Maybe I should email Anders Hejlsberg :-) |
@sofayam |
Facing the same problem. |
@bhushankumar-developer fortunately yes, I resolved it: namespace definition could be imported by triple-slash directive Another way to import it is to play with tsconfig.json file, in my case I edited "typeRoots" section. |
Finally I've completed to write the entire API typings for this project, in order to help any other poor TypeScript developer like me that is used to have types for everything :) For any other typescript maniac, you can get the typings from both npm register, either github, just follow these links (sorry for any error I may have done, I've write it in just 3 days):
Any help or comment would be appreciated. |
In Angular 6 is easy, It works for me:
|
@codealvarez that package provides typings for JavaScript API / we're talking about the Node API |
@indrimuska looks like they now have a way to support this via underscores in the name for definitely typed. Might be worth looking to see about publishing? Great work |
Glad I read this entire thread to stumble upon your typings library. Thank you for taking the time to do that! If you want to get more mileage from the work you did on this, though, you should really consider publishing it to DefinitelyTyped. |
FYI, @indrimuska package is now available as part of DefinitelyTyped: |
Consider importing 'google-maps' instead of '@types/google-maps' |
I've solved the problem declaring the namespace in the top of the file, like this: |
I feel this #42 (comment) should be added to the main README... :) Thanks for that ! |
@brettatoms can you please update your README with the accepted solutions here? Maybe add a 'typescript considerations' section? It's probably almost mandatory at this point for node.js repositories to include such information. Much appreciation on the client library. Thanks. |
@amak07 I only created this issue. I don't have a README to update. |
+1 for |
Added this to the README in b1a82da Thanks for contributing! =) |
Rather than installing the third-party https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html This way, we don't have to install both this package and the I'm happy to help convert if interested. |
@grant I'm going to reopen this and try to find time to convert to typescript. shouldn't take too long... hopefully 😄 |
LMK if you need help 👍 |
Did this. Worked pretty well import { google } from 'google-maps'; |
TypeScript support is provided in @googlemaps/google-maps-services-js. There is a migration guide in the README.md as the API has changed from @google/maps. |
No description provided.
The text was updated successfully, but these errors were encountered: