Skip to content

Commit

Permalink
Get ride of the src/types
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed May 22, 2024
1 parent 263365b commit df31dcf
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 46 deletions.
3 changes: 1 addition & 2 deletions src/source/load_tilejson.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {pick, extend} from '../util/util';
import {pick, extend, TileJSON} from '../util/util';
import {getJSON} from '../util/ajax';
import {ResourceType} from '../util/request_manager';
import {browser} from '../util/browser';

import type {RequestManager} from '../util/request_manager';
import type {TileJSON} from '../types/tilejson';
import type {RasterDEMSourceSpecification, RasterSourceSpecification, VectorSourceSpecification} from '@maplibre/maplibre-gl-style-spec';

export type LoadTileJsonResponse = {
Expand Down
16 changes: 0 additions & 16 deletions src/types/tilejson.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/types/util.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/ui/map.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {extend, warnOnce, uniqueId, isImageBitmap} from '../util/util';
import {extend, warnOnce, uniqueId, isImageBitmap, Complete} from '../util/util';
import {browser} from '../util/browser';
import {DOM} from '../util/dom';
import packageJSON from '../../package.json' with {type: 'json'};
Expand Down Expand Up @@ -58,7 +58,6 @@ import type {
import type {MapGeoJSONFeature} from '../util/vectortile_to_geojson';
import type {ControlPosition, IControl} from './control/control';
import type {QueryRenderedFeaturesOptions, QuerySourceFeatureOptions} from '../source/query_features';
import {Complete} from '../types/util';

const version = packageJSON.version;

Expand Down
42 changes: 42 additions & 0 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,3 +668,45 @@ export function subscribe(target: Subscriber, message: keyof WindowEventMap, lis
export function degreesToRadians(degrees: number): number {
return degrees * Math.PI / 180;
}

/**
* Makes optional keys required and add the the undefined type.
*
* ```
* interface Test {
* foo: number;
* bar?: number;
* baz: number | undefined;
* }
*
* Complete<Test> {
* foo: number;
* bar: number | undefined;
* baz: number | undefined;
* }
*
* ```
*
* See https://medium.com/terria/typescript-transforming-optional-properties-to-required-properties-that-may-be-undefined-7482cb4e1585
*/

export type Complete<T> = {
[P in keyof Required<T>]: Pick<T, P> extends Required<Pick<T, P>> ? T[P] : (T[P] | undefined);
}

export type TileJSON = {
tilejson: '2.2.0' | '2.1.0' | '2.0.1' | '2.0.0' | '1.0.0';
name?: string;
description?: string;
version?: string;
attribution?: string;
template?: string;
tiles: Array<string>;
grids?: Array<string>;
data?: Array<string>;
minzoom?: number;
maxzoom?: number;
bounds?: [number, number, number, number];
center?: [number, number, number];
vector_layers: [{id: string}]; // this is partial but enough for what we need
};
2 changes: 1 addition & 1 deletion test/bench/lib/tile_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {StyleLayerIndex} from '../../../src/style/style_layer_index';
import type {StyleSpecification} from '@maplibre/maplibre-gl-style-spec';
import type {WorkerTileResult} from '../../../src/source/worker_source';
import type {OverscaledTileID} from '../../../src/source/tile_id';
import type {TileJSON} from '../../../src/types/tilejson';
import type {TileJSON} from '../../../src/util/util';
import type {Map} from '../../../src/ui/map';
import type {IActor} from '../../../src/util/actor';
import {MessageType} from '../../../src/util/actor_messages';
Expand Down

0 comments on commit df31dcf

Please sign in to comment.