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

Fixed a TypeScript Error #1687

Merged
merged 1 commit into from
Oct 18, 2017
Merged

Fixed a TypeScript Error #1687

merged 1 commit into from
Oct 18, 2017

Conversation

PaitoAnderson
Copy link
Contributor

Fix a bug I found after submitting PR #1601.

I was getting this error:
[TS] Exports and export assignments are not permitted in module augmentations.

Thanks!

@luiseduardobrito
Copy link

Also having this issue, waiting for the merge.

@gpeal gpeal merged commit 8f0b21e into react-native-maps:master Oct 18, 2017
@SrikanthKabadi
Copy link

SrikanthKabadi commented Oct 18, 2017

Hi @PaitoAnderson @gpeal ,

Getting this exception when I am trying to load MapView from .tsx file.

Same works beautifully if I load it from Javascript(.js) file. Please help.

Unhandled JS Exception: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.

// MapComponent.tsx
import MapView from 'react-native-maps'
export class MapComponent extends React.Component {
    render() {
        return (
            <View style={styles.container}>
                <MapView
                    style={styles.map}
                    initialRegion={{
                        latitude: 12.934533,
                        longitude: 77.626579,
                        latitudeDelta: 0.0922,
                        longitudeDelta: 0.0421
                    }}
                />
            </View>
        )
    }
}

simulator screen shot - iphone 7 plus - 2017-10-18 at 18 17 33

@luiseduardobrito
Copy link

@SrikanthKabadi

Have you tried: import * as MapView from 'react-native-maps?

@PaitoAnderson PaitoAnderson deleted the patch-1 branch October 18, 2017 17:42
@SrikanthKabadi
Copy link

@luiseduardobrito Brilliant, it worked :) Thank you so much :)

@marcmo
Copy link

marcmo commented Nov 5, 2017

@PaitoAnderson adding support for typescript is greatly appreciated! To make it easier to use this package with typescript, would you mind adding a little example? I first struggled with the import issue, but I still cannot get my code to typecheck. e.g. I use a Callout with a style attribute, but the typescript definitions do not seem to find it.

error TS2339: Property 'style' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Callout> & Readonly<{ children?: ReactNode; }> & R...'.

or more visible even: where is the definition for PROVIDER_DEFAULT etc.?

error TS2304: Cannot find name 'PROVIDER_DEFAULT'.

having a little example to start with would for sure help the typescript users. For my part I switched back to 0.16.4 since I did not find a quick solution.

@PaitoAnderson
Copy link
Contributor Author

PaitoAnderson commented Nov 5, 2017

@marcmo Here is a quick example, looks like I forgot the style property for <MapView.Callout>. I'll do a quick PR to add it, maybe I should just inherit from View props or something. I am surprised it crashes for you though, it just warns me in Visual Studio Code if I use it anyway.

import React, { Component } from 'react';
import { Dimensions, StyleSheet, Text, View } from 'react-native';
import MapView from 'react-native-maps';

const { width, height } = Dimensions.get('window');

const ASPECT_RATIO = width / height;
const LATITUDE_DELTA = 0.25;
const LONGITUDE_DELTA = LATITUDE_DELTA * ASPECT_RATIO;
const ZOOM_LEVEL = 1;

interface IMarker {
    Title: string;
    Coordinates: {
        latitude: number;
        longitude: number;
    };
}

interface IProps { navigation: any; }
interface IState { location: IMarker; }

const styles = StyleSheet.create({
    map: {
        flex: 1,
    },
});

class ExampleMap extends React.PureComponent<IProps, IState> {

    private map: any;
    private locationMarker: any;

    constructor(props: IProps) {
        super(props);

        const initialState = {
            location: {
                Coordinates: {
                    latitude: 42.2951067,
                    longitude: -83.0729218,
                },
                Title: 'Hi @marcmo!',
            },
        } as IState;

        this.state = initialState;
    }

    public render() {
        return (<MapView
            provider={'google'}
            ref={(ref: any) => (this.map = ref)}
            style={styles.map}
            showsScale={true}
            loadingEnabled={true}
            showsCompass={true}
            onLayout={this.onLayout.bind(this)}
            mapType={'standard'}>
                <MapView.Marker ref={(ref: any) => (this.locationMarker = ref)}
                    coordinate={this.state.location.Coordinates}>
                    <MapView.Callout>
                        <Text style={{ color: 'blue' }}>{this.state.location.Title}</Text>
                    </MapView.Callout>
                </MapView.Marker>
            </MapView>);
    }

    private onLayout = () => {
        const zoomCoordinates = {
            latitude: this.state.location.Coordinates.latitude,
            latitudeDelta: LATITUDE_DELTA / ZOOM_LEVEL,
            longitude: this.state.location.Coordinates.longitude,
            longitudeDelta: LONGITUDE_DELTA / ZOOM_LEVEL,
        };
        this.map.animateToRegion(zoomCoordinates);

        if (this.locationMarker) {
            this.locationMarker.showCallout();
        }
    }
}

export default ExampleMap;

simulator screen shot - iphone 6 - 2017-11-05 at 13 59 44

@marcmo
Copy link

marcmo commented Nov 6, 2017

super awesome @PaitoAnderson ! I bet this will help others as well.

christopherdro pushed a commit that referenced this pull request Nov 28, 2017
* Added style prop to MapCalloutProps in Typings

Fixes @marcmo issue in #1687

* Update index.d.ts

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

Successfully merging this pull request may close these issues.

None yet

5 participants