Skip to content

Commit 65e3242

Browse files
Migrate to TypeScript: initial commit (#1268)
1 parent 45555af commit 65e3242

File tree

81 files changed

+1378
-1112
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1378
-1112
lines changed

.eslintrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// prettier-ignore
22
module.exports = {
33
parser: 'babel-eslint',
4-
plugins: ['flowtype', 'react'],
5-
extends: ['uber-jsx', 'uber-es2015', 'prettier', 'prettier/react', 'prettier/flowtype', 'plugin:import/errors', 'plugin:flowtype/recommended'],
4+
plugins: ['react', '@typescript-eslint'],
5+
extends: ['uber-jsx', 'uber-es2015', 'prettier', 'prettier/react', 'plugin:import/errors'],
66
overrides: [{
77
files: ['*.spec.js', 'webpack.config.js', '**/bundle/*.js'],
88
rules: {

.flowconfig

Lines changed: 0 additions & 14 deletions
This file was deleted.

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const getBabelConfig = require('ocular-dev-tools/config/babel.config');
44
module.exports = api => {
55
const config = getBabelConfig(api);
66

7-
config.presets = (config.presets || []).concat(['@babel/flow', '@babel/preset-react']);
7+
config.presets = (config.presets || []).concat(['@babel/preset-react']);
88
config.plugins = (config.plugins || []).concat('@babel/proposal-class-properties');
99

1010
return config;

examples/webpack.config.local.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const LIB_DIR = resolve(__dirname, '..');
1212
const SRC_DIR = resolve(LIB_DIR, './src');
1313

1414
const BABEL_CONFIG = {
15-
presets: ['@babel/env', '@babel/react', '@babel/flow'],
15+
presets: ['@babel/env', '@babel/react'],
1616
plugins: ['@babel/proposal-class-properties']
1717
};
1818

flow-typed/npm/mapbox-gl_vx.x.x.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

flow-typed/npm/math.gl_vx.x.x.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

flow-typed/npm/mjolnir.js_vx.x.x.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

flow-typed/npm/prop-types_v15.x.x.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

flow-typed/npm/react-virtualized-auto-sizer_vx.x.x.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

flow-typed/npm/viewport-mercator-project_vx.x.x.js

Lines changed: 0 additions & 53 deletions
This file was deleted.

package.json

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"url": "https://github.com/visgl/react-map-gl.git"
1515
},
1616
"license": "MIT",
17+
"types": "src/index.d.ts",
1718
"main": "dist/es5/index.js",
1819
"module": "dist/esm/index.js",
1920
"esnext": "dist/es6/index.js",
@@ -29,20 +30,24 @@
2930
"README.md"
3031
],
3132
"scripts": {
32-
"typecheck": "flow check",
33+
"typecheck": "tsc",
3334
"start": "(cd examples/controls && yarn && yarn start-local)",
3435
"bootstrap": "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true yarn && ocular-bootstrap",
3536
"clean": "ocular-clean",
36-
"build": "ocular-clean && ocular-build",
37+
"build": "ocular-clean && ocular-build && npm run flowgen",
38+
"flowgen": "for i in $(find dist -type f -name \"*.d.ts\"); do sh -c \"flowgen $i -o ${i%.*.*}.js.flow\"; done;",
3739
"lint": "ocular-lint",
3840
"cover": "ocular-test cover",
3941
"publish-prod": "ocular-publish prod",
4042
"publish-beta": "ocular-publish beta",
41-
"test": "flow check && ocular-test",
42-
"test-fast": "flow check && ocular-test fast",
43+
"test": "tsc && ocular-test",
44+
"test-fast": "tsc && ocular-test node",
4345
"metrics": "ocular-metrics",
4446
"update-release-branch": "scripts/update-release-branch.sh"
4547
},
48+
"resolutions": {
49+
"prettier": "1.14.3"
50+
},
4651
"dependencies": {
4752
"@babel/runtime": "^7.0.0",
4853
"mapbox-gl": "^2.0.0",
@@ -53,21 +58,20 @@
5358
},
5459
"devDependencies": {
5560
"@babel/plugin-proposal-class-properties": "^7.4.4",
56-
"@babel/plugin-transform-flow-strip-types": "^7.4.4",
5761
"@babel/polyfill": "^7.0.0",
58-
"@babel/preset-flow": "^7.0.0",
5962
"@babel/preset-react": "^7.0.0",
6063
"@babel/register": "^7.0.0",
6164
"@probe.gl/bench": "^3.2.1",
6265
"@probe.gl/test-utils": "^3.2.1",
66+
"@types/react": "^16.0.0",
67+
"@typescript-eslint/eslint-plugin": "^4.0.0",
6368
"babel-eslint": "^10.0.1",
6469
"babel-loader": "^8.0.0",
6570
"coveralls": "^3.0.0",
6671
"eslint-config-uber-jsx": "^3.3.3",
67-
"eslint-plugin-flowtype": "^3.7.0",
6872
"eslint-plugin-import": "^2.16.0",
6973
"eslint-plugin-react": "^7.10",
70-
"flow-bin": "^0.98.1",
74+
"flowgen": "^1.12.1",
7175
"immutable": "^3.8.2",
7276
"jsdom": "^15.0.0",
7377
"ocular-dev-tools": "^0.1.8",
@@ -76,7 +80,8 @@
7680
"react-dom": "^16.3.0",
7781
"react-test-renderer": "^16.3.0",
7882
"reify": "^0.18.1",
79-
"sinon": "4.1.3"
83+
"sinon": "4.1.3",
84+
"typescript": "^4.0.0"
8085
},
8186
"peerDependencies": {
8287
"react": ">=16.3.0"

src/components/base-control.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {MapControlProps} from './use-map-control';
2+
import {MjolnirEvent} from '../utils/map-controller';
3+
4+
export default class BaseControl {
5+
6+
static defaultProps: MapControlProps;
7+
8+
_context: any;
9+
_containerRef: {current: null | HTMLElement | SVGAElement};
10+
11+
_onScroll(evt: MjolnirEvent) : void;
12+
13+
_onDragStart(evt: MjolnirEvent) : void;
14+
15+
_onDblClick(evt: MjolnirEvent) : void;
16+
17+
_onClick(evt: MjolnirEvent) : void;
18+
19+
_onPointerMove(evt: MjolnirEvent) : void;
20+
21+
}

src/components/base-control.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @flow
21
// Copyright (c) 2015 Uber Technologies, Inc.
32

43
// Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -22,12 +21,7 @@ import * as React from 'react';
2221
import {PureComponent, createRef} from 'react';
2322
import useMapControl, {mapControlDefaultProps, mapControlPropTypes} from './use-map-control';
2423

25-
import type {MjolnirEvent} from 'mjolnir.js';
26-
import type {MapControlProps} from './use-map-control';
27-
28-
export type BaseControlProps = MapControlProps;
29-
30-
function Control(props: any) {
24+
function Control(props) {
3125
const {instance} = props;
3226
const {context, containerRef} = useMapControl(instance.props, props);
3327

@@ -40,26 +34,22 @@ function Control(props: any) {
4034
/*
4135
* This class is kept for backward compatibility
4236
*/
43-
export default class BaseControl<
44-
Props: BaseControlProps,
45-
State: any,
46-
ContainerType: Element
47-
> extends PureComponent<Props, State> {
37+
export default class BaseControl extends PureComponent {
4838
static propTypes = mapControlPropTypes;
4939
static defaultProps = mapControlDefaultProps;
5040

51-
_context: any = {};
52-
_containerRef: {current: null | ContainerType} = createRef();
41+
_context = {};
42+
_containerRef = createRef();
5343

54-
_onScroll = (evt: MjolnirEvent) => {};
44+
_onScroll = evt => {};
5545

56-
_onDragStart = (evt: MjolnirEvent) => {};
46+
_onDragStart = evt => {};
5747

58-
_onDblClick = (evt: MjolnirEvent) => {};
48+
_onDblClick = evt => {};
5949

60-
_onClick = (evt: MjolnirEvent) => {};
50+
_onClick = evt => {};
6151

62-
_onPointerMove = (evt: MjolnirEvent) => {};
52+
_onPointerMove = evt => {};
6353

6454
_render() {
6555
throw new Error('_render() not implemented');

0 commit comments

Comments
 (0)