Skip to content

Commit 9348083

Browse files
wipfliHarelM
andauthored
Fix TypeScript typings (#787)
Fixes #776 * Initial commit to fix array types * Rename get/setType to get/setSourceType * Last fixes beside conflict in dom.d.ts * Fix build * Fix lint * Fix rename * Fix types in tests * Fix type error in test * Copy grid-index from mapbox and migrate to TypeScript * Add vector tile to declaration file * Copy grid-index unit tests from mapbox * Move static methods into the right class * Added serialization test, bump version, added changelog remarks * Move @types/pbf to dependencies Co-authored-by: HarelM <harel.mazor@gmail.com>
1 parent a99adaa commit 9348083

21 files changed

Lines changed: 368 additions & 125 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
- *...Add new stuff here...*
1010

11+
## 2.0.2
12+
13+
### 🐞 Bug fixes
14+
15+
- Fix typescript generated file (#776).
16+
1117
## 2.0.1
1218

1319
### 🐞 Bug fixes

build/generate-struct-arrays.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function createStructArrayType(name: string, layout: StructArrayLayout, includeS
8787
includeStructAccessors
8888
});
8989
} else {
90-
arrayTypeEntries.add(`${layoutClass} as ${arrayClass}`);
90+
arrayTypeEntries.add(`export class ${arrayClass} extends ${layoutClass} {}`);
9191
}
9292
}
9393

@@ -432,8 +432,8 @@ import Point from '../util/point';
432432
433433
${layouts.map(emitStructArrayLayout).join('\n')}
434434
${arraysWithStructAccessors.map(emitStructArray).join('\n')}
435+
${[...arrayTypeEntries].join('\n')}
435436
export {
436-
${layouts.map(layout => layout.className).join(',\n ')},
437-
${[...arrayTypeEntries].join(',\n ')}
437+
${layouts.map(layout => layout.className).join(',\n ')}
438438
};
439439
`);

build/post-ts-build.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,17 @@ console.log(`Starting bundling types`);
3535
const outputFile = "./dist/maplibre-gl.d.ts";
3636
child_process.execSync(`dts-bundle-generator --no-check --umd-module-name=maplibregl -o ${outputFile} ./src/index.ts`);
3737
let types = fs.readFileSync(outputFile, 'utf8');
38+
// Classes are not exported but should be since this is exported as UMD - fixing...
3839
types = types.replace(/declare class/g, "export declare class");
40+
// Missing vector-tile types that are added to this file too
41+
let file = fs.readFileSync("./src/types/packages-types/vector-tile/index.d.ts", 'utf8');
42+
let lines = file.split("\n").filter(Boolean);
43+
lines.pop(); // last } is removed too.
44+
types = lines.join("\n") + "\n" + types;
45+
// remove imports of vector-tile and declare module lines
46+
types = types.split("\n")
47+
.filter(l => !l.includes("@mapbox/vector-tile"))
48+
.join("\n");
3949
fs.writeFileSync(outputFile, types);
4050
console.log(`Finished bundling types`);
4151

package-lock.json

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "maplibre-gl",
33
"description": "BSD licensed community fork of mapbox-gl, a WebGL interactive maps library",
4-
"version": "2.0.1",
4+
"version": "2.0.2",
55
"main": "dist/maplibre-gl.js",
66
"style": "dist/maplibre-gl.css",
77
"license": "BSD-3-Clause",
@@ -22,11 +22,11 @@
2222
"@mapbox/unitbezier": "^0.0.1",
2323
"@mapbox/vector-tile": "^1.3.1",
2424
"@mapbox/whoots-js": "^3.1.0",
25+
"@types/pbf": "^3.0.2",
2526
"csscolorparser": "~1.0.3",
2627
"earcut": "^2.2.2",
2728
"geojson-vt": "^3.2.1",
2829
"gl-matrix": "^3.2.1",
29-
"grid-index": "^1.1.0",
3030
"murmurhash-js": "^1.0.0",
3131
"pbf": "^3.2.1",
3232
"potpack": "^1.0.1",
@@ -69,7 +69,6 @@
6969
"@types/node-notifier": "^8.0.0",
7070
"@types/npm-packlist": "^1.1.1",
7171
"@types/offscreencanvas": "^2019.6.3",
72-
"@types/pbf": "^3.0.2",
7372
"@types/pixelmatch": "^5.2.2",
7473
"@types/pngjs": "^6.0.1",
7574
"@types/puppeteer": "^5.4.4",

src/data/array_types.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,25 @@ export class FeatureIndexArray extends StructArrayLayout1ul2ui8 {
10311031

10321032
register('FeatureIndexArray', FeatureIndexArray);
10331033

1034+
export class PosArray extends StructArrayLayout2i4 {}
1035+
export class RasterBoundsArray extends StructArrayLayout4i8 {}
1036+
export class CircleLayoutArray extends StructArrayLayout2i4 {}
1037+
export class FillLayoutArray extends StructArrayLayout2i4 {}
1038+
export class FillExtrusionLayoutArray extends StructArrayLayout2i4i12 {}
1039+
export class HeatmapLayoutArray extends StructArrayLayout2i4 {}
1040+
export class LineLayoutArray extends StructArrayLayout2i4ub8 {}
1041+
export class LineExtLayoutArray extends StructArrayLayout2f8 {}
1042+
export class PatternLayoutArray extends StructArrayLayout10ui20 {}
1043+
export class SymbolLayoutArray extends StructArrayLayout4i4ui4i24 {}
1044+
export class SymbolDynamicLayoutArray extends StructArrayLayout3f12 {}
1045+
export class SymbolOpacityArray extends StructArrayLayout1ul4 {}
1046+
export class CollisionBoxLayoutArray extends StructArrayLayout2i2i2i12 {}
1047+
export class CollisionCircleLayoutArray extends StructArrayLayout2f1f2i16 {}
1048+
export class CollisionVertexArray extends StructArrayLayout2ub2f12 {}
1049+
export class QuadTriangleArray extends StructArrayLayout3ui6 {}
1050+
export class TriangleIndexArray extends StructArrayLayout3ui6 {}
1051+
export class LineIndexArray extends StructArrayLayout2ui4 {}
1052+
export class LineStripIndexArray extends StructArrayLayout1ui2 {}
10341053
export {
10351054
StructArrayLayout2i4,
10361055
StructArrayLayout4i8,
@@ -1053,24 +1072,5 @@ export {
10531072
StructArrayLayout1ul2ui8,
10541073
StructArrayLayout2ui4,
10551074
StructArrayLayout1ui2,
1056-
StructArrayLayout4f16,
1057-
StructArrayLayout2i4 as PosArray,
1058-
StructArrayLayout4i8 as RasterBoundsArray,
1059-
StructArrayLayout2i4 as CircleLayoutArray,
1060-
StructArrayLayout2i4 as FillLayoutArray,
1061-
StructArrayLayout2i4i12 as FillExtrusionLayoutArray,
1062-
StructArrayLayout2i4 as HeatmapLayoutArray,
1063-
StructArrayLayout2i4ub8 as LineLayoutArray,
1064-
StructArrayLayout2f8 as LineExtLayoutArray,
1065-
StructArrayLayout10ui20 as PatternLayoutArray,
1066-
StructArrayLayout4i4ui4i24 as SymbolLayoutArray,
1067-
StructArrayLayout3f12 as SymbolDynamicLayoutArray,
1068-
StructArrayLayout1ul4 as SymbolOpacityArray,
1069-
StructArrayLayout2i2i2i12 as CollisionBoxLayoutArray,
1070-
StructArrayLayout2f1f2i16 as CollisionCircleLayoutArray,
1071-
StructArrayLayout2ub2f12 as CollisionVertexArray,
1072-
StructArrayLayout3ui6 as QuadTriangleArray,
1073-
StructArrayLayout3ui6 as TriangleIndexArray,
1074-
StructArrayLayout2ui4 as LineIndexArray,
1075-
StructArrayLayout1ui2 as LineStripIndexArray
1075+
StructArrayLayout4f16
10761076
};

src/data/bucket/fill_bucket.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ test('FillBucket', () => {
4242
new Point(10, 20)
4343
]], undefined, undefined, undefined);
4444

45-
bucket.addFeature(feature, feature.loadGeometry(), undefined, undefined, undefined);
45+
bucket.addFeature(feature as any, feature.loadGeometry(), undefined, undefined, undefined);
4646
}).not.toThrow();
4747
});
4848

src/data/bucket/line_bucket.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe('LineBucket', () => {
9696
new Point(0, 0)
9797
], polygon, undefined, undefined, undefined, undefined);
9898

99-
bucket.addFeature(feature, feature.loadGeometry(), undefined, undefined, undefined);
99+
bucket.addFeature(feature as any, feature.loadGeometry(), undefined, undefined, undefined);
100100
}).not.toThrow();
101101
});
102102

src/data/feature_index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import loadGeometry from './load_geometry';
33
import toEvaluationFeature from './evaluation_feature';
44
import EXTENT from './extent';
55
import featureFilter from '../style-spec/feature_filter';
6-
import TransferableGridIndex from 'grid-index';
6+
import TransferableGridIndex from '../util/transferable_grid_index';
77
import DictionaryCoder from '../util/dictionary_coder';
88
import vt from '@mapbox/vector-tile';
99
import Protobuf from 'pbf';
@@ -296,7 +296,7 @@ class FeatureIndex {
296296
let id: string | number = feature.id;
297297
if (this.promoteId) {
298298
const propName = typeof this.promoteId === 'string' ? this.promoteId : this.promoteId[sourceLayerId];
299-
id = feature.properties[propName];
299+
id = feature.properties[propName] as string | number;
300300
if (typeof id === 'boolean') id = Number(id);
301301
}
302302
return id;

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/// <reference path="./types/glsl.d.ts" />
2-
/// <reference path="./types/non-typed-modules.d.ts" />
32
import assert from 'assert';
43
import {supported} from '@mapbox/mapbox-gl-supported';
54

0 commit comments

Comments
 (0)