Skip to content
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

Create TypeScript definitions #363

Closed
tomchentw opened this issue Oct 14, 2016 · 37 comments · Fixed by #646
Closed

Create TypeScript definitions #363

tomchentw opened this issue Oct 14, 2016 · 37 comments · Fixed by #646

Comments

@tomchentw
Copy link
Owner

No description provided.

@tomchentw
Copy link
Owner Author

Anyone interested?

@gochi-dot
Copy link

@tomchentw Yes. Please create definition. I am using typescript on my project, but there are no .d.ts gile for maps. Thank you.

@mxl
Copy link
Contributor

mxl commented May 26, 2017

Should I create PR here or in https://github.com/DefinitelyTyped/DefinitelyTyped?

@tomchentw
Copy link
Owner Author

@mxl you can create PR here.

@AAllport
Copy link

Any update on this?

@oshalygin
Copy link
Collaborator

I haven't used typescript in about a year, going to defer this to someone else thats more familiar and can crank it out without reading alot of docs

@mxl
Copy link
Contributor

mxl commented Aug 24, 2017 via email

@tomchentw
Copy link
Owner Author

@mxl you're awesome!

@mxl
Copy link
Contributor

mxl commented Sep 6, 2017

@tomchentw Sorry, I was busy on that weekend. I will finish the work this week.

@tomchentw
Copy link
Owner Author

No rush.

@kenjiru
Copy link

kenjiru commented Sep 24, 2017

@mxl no rush, but please keep us posted regarding the progress on this issue.

@simran5
Copy link

simran5 commented Oct 3, 2017

also interested in this

@tomchentw
Copy link
Owner Author

PR's are welcomed!
Also, you may be interested to generate typed code from src/macro directly using jscodeshift API. That could save you lots of time.

@mxl mxl mentioned this issue Oct 5, 2017
4 tasks
@mxl
Copy link
Contributor

mxl commented Oct 5, 2017

Guys, sorry for late response. I've continued my work on definitions. See #646.

@mxl
Copy link
Contributor

mxl commented Oct 6, 2017

I've almost finished definitions. You can test them by installing react-google-maps with npm install github:mxl/react-google-maps#typescript-definitions.

@ChuckJonas
Copy link

also interested

tomchentw pushed a commit that referenced this issue Nov 24, 2017
@tomchentw
Copy link
Owner Author

Released v9.3.0

@israellev
Copy link

israellev commented Jan 4, 2018

If you has an error like - Cannot find namespace 'google' or Cannot find name 'Calculator':
pay attention that in library in node_modules/react-google-maps/package.json it's a peerDependencies that you relay need:
npm i --save @types/googlemaps
npm i --save @types/markerclustererplus

and it's spouse to work.

@afholderman
Copy link

Has anyone been able to get this to work that can share an example? Using examples from the documentation I'm still met with TS errors.

@mxl
Copy link
Contributor

mxl commented Jan 10, 2018

@afholderman What errors do you have?

@afholderman
Copy link

afholderman commented Jan 10, 2018

@mxl

Given this component (imports left out to keep it shorter):

export const MyGoogleMap = compose(
  withProps({
    googleMapURL: 'https://maps.googleapis.com/maps/api/js?key=[removed]&v=3.exp&libraries=geometry,drawing,places',
    loadingElement: <div style={{ height: '100%' }} />,
    containerElement: <div style={{ height: '400px' }} />,
    mapElement: <div style={{ height: '100%' }} />,
  }),
  withScriptjs,
  withGoogleMap
  )( (props) => (
    <GoogleMap
      defaultZoom={8}
      defaultCenter={{ lat: -34.397, lng: 150.644 }}
      center={props.center}
    />
  )
);

<MyGoogleMap
  center={{ lat: 38.6270, lng: -90.1994 }}
/>

Typescript throwing the error: TS2339: Property 'center' does not exist on type '{ children?: ReactNode; }'.
Even though center is a documented prop on the GoogleMap component. I tested this same component in a non-Typescript create-react-app and it works as expected.

@mxl
Copy link
Contributor

mxl commented Jan 10, 2018

@afholderman I think that this error is about props that you pass to closure that returns GoogleMap element, not about GoogleMap props.

@bharney
Copy link

bharney commented Jan 15, 2018

In addition to installing the type definitions for @types/googlemaps @types/markerclustererplus I also needed to add them to my configuration to resolve errors related to: 'Cannot find name 'Calculator'. or 'Cannot find module 'google'.
I added the following to my tsconfig.json

"types": [
      "googlemaps",
      "markerclustererplus"
 ],

And it works now!

@atrauzzi
Copy link

You shouldn't have to do that, the types should auto-discover once in the node_modules folder. Any chance you can show the rest of your tsconfig.json?

@laukaichung
Copy link

laukaichung commented Feb 1, 2018

Anyone using Webstorm? I'm getting a warning about Cannot find parent 'tsconfig.json' from /.../node_modules/@ types/googlemaps/index.d.ts

@AAllport
Copy link

AAllport commented Feb 1, 2018 via email

@laukaichung
Copy link

laukaichung commented Feb 1, 2018

@AAllport
I installed the type file with npm i --save @types/googlemaps
I think the problem comes from the exclude settings in tsconfig.json

{
  "compileOnSave": true,
  "compilerOptions": {
    "module": "commonjs",
    "target": "es2015"
  },
  "exclude": [
    "node_modules"
  ]
}

The warning disappears after "node_modules" is removed.

@AAllport
Copy link

AAllport commented Feb 1, 2018 via email

@Anees-Raja
Copy link

Do I need webpack or a bundler to use this component? I keep getting the following error:

./src/app/components/CustomMap/CustomMap.js Module parse failed: \src\app\components\CustomMap\CustomMap.js Unexpected token (6:4) You may need an appropriate loader to handle this file type. | | const CustomMap = withScriptjs(withGoogleMap((props) => | <GoogleMap | defaultZoom={8} | defaultCenter={{ lat: -34.397, lng: 150.644 }}

@baughmann
Copy link

Why is this closed?

@digital-nomad17
Copy link

@mxl
Has your type definitions for react-google-maps been merged? I can't find on npm.

@mxl
Copy link
Contributor

mxl commented May 30, 2018

@digital-nomad17 Yes, they are installed with this module. Also you need definitions for googlemaps and markerclustererplus modules:

npm i --save react-google-maps @types/googlemaps @types/markerclustererplus

@digital-nomad17
Copy link

@mxl
Thank you!

Can we add notes to the github page for the typedefiniton file so people can find them?

@mxl
Copy link
Contributor

mxl commented May 30, 2018

@digital-nomad17 Actually it's better to move definitions to separate module and make it depend on @types/googlemaps and @types/marlerclustererplus or add them to dependencies for this module. @tomchentw what is your decision?

@baughmann
Copy link

@mxl running npm i --save react-google-maps @types/googlemaps @types/markerclustererplus and then importing import {GoogleMap, withGoogleMap, withScriptjs} from 'react-google-maps' results in a bunch of TS2503: Cannot find namespace 'google'.. Is this the expected result? Is there more work to do on my end?

@williamsb
Copy link

Just an FYI for anyone having trouble importing snazzymaps styles (on typescript), make sure you are using the correct type for "stylers"
snazzymaps default:

"stylers": [ { "saturation": "13" }, { "lightness": "4" } ]

should be:

"stylers": [ { "saturation": 13 }, { "lightness": 4 } ]

types based on:


export interface MapTypeStyler {
   color?: string;
   gamma?: number;
   hue?: string;
   invert_lightness?: boolean;
   lightness?: number;
   saturation?: number;
   visibility?: string;
   weight?: number;
}

@alamothe
Copy link

alamothe commented Oct 7, 2018

Impressive type definitions!

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

Successfully merging a pull request may close this issue.