Skip to content

Commit a46a03c

Browse files
authored
Merge pull request #54 from no23reason/features/typings-fix
Features/typings fix
2 parents d29f662 + d571fe0 commit a46a03c

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

index.d.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,17 @@ interface GeolocatedProps {
4141
positionError?: PositionError;
4242
}
4343

44-
declare class ElementClass extends React.Component<GeolocatedProps, any> { }
45-
interface ClassDecorator {
46-
<T extends (typeof ElementClass)>(component: T): T;
44+
type ComponentType = React.ComponentClass<GeolocatedProps> | React.StatelessComponent<GeolocatedProps>;
45+
46+
interface ComponentDecorator {
47+
<TargetClass extends ComponentType>(component: TargetClass): TargetClass;
4748
}
4849

4950
/**
5051
* The HOC function.
5152
*/
52-
export function geolocated(config?: GeolocatedConfig): ClassDecorator;
53+
export function geolocated(config?: GeolocatedConfig): ComponentDecorator;
5354
/**
5455
* React propTypes object.
5556
*/
56-
export const geoPropTypes: React.ValidationMap<ElementClass>;
57+
export const geoPropTypes: React.ValidationMap<ComponentType>;

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"version": "0.0.0-semantic-release",
77
"scripts": {
88
"start": "webpack-dev-server",
9-
"test": "jest --coverage",
9+
"test": "npm run test:lint && npm run test:js && npm run test:ts",
10+
"test:js": "jest --coverage",
1011
"test:tdd": "jest --watch",
1112
"test:lint": "eslint . --ext .js --ext .jsx --ignore-path .gitignore --ignore-pattern dist --ignore-pattern docs --cache",
1213
"test:ts": "cd tests/typescript && rimraf out && rimraf typings && typings install && tsc && rimraf out && rimraf typings",
@@ -77,7 +78,7 @@
7778
],
7879
"license": "MIT",
7980
"pre-push": [
80-
"test",
81+
"test:js",
8182
"test:lint"
8283
],
8384
"config": {

tests/typescript/index.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ class Demo extends React.Component<IDemoProps, {}> {
1414
}
1515
}
1616

17+
function StatelessDemo(props: GeolocatedProps): React.ReactElement<{}> {
18+
return <div>
19+
latitude: {props.coords && props.coords.latitude}
20+
isGeolocationAvailable: {props.isGeolocationAvailable}
21+
isGeolocationEnabled: {props.isGeolocationEnabled}
22+
positionError: {props.positionError}
23+
</div>;
24+
}
25+
26+
const StatelessDemoWrapped = geolocated()(StatelessDemo);
27+
1728
export default geolocated({
1829
userDecisionTimeout: 5000,
1930
positionOptions: {

0 commit comments

Comments
 (0)