Skip to content

Commit

Permalink
Strict TS for demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Fsss126 committed Jan 11, 2024
1 parent 0badb57 commit 402c63d
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 74 deletions.
2 changes: 1 addition & 1 deletion demo/src/components/AppSidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
export let noHeader = false;
const meta = examples.find((example) => example.path === $location);
const meta = examples.find((example) => example.path === $location)!;
</script>

<aside class="basis-full lg:basis-1/3 overflow-hidden shadow-xl">
Expand Down
12 changes: 6 additions & 6 deletions demo/src/examples/1 User Interaction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import style from "../assets/map/style/style.json?url";
import MapLibreGlDirections from "@maplibre/maplibre-gl-directions";
const meta = examples.find((example) => example.path === $location);
const meta = examples.find((example) => example.path === $location)!;
let mapRef: HTMLElement | undefined = undefined;
let map: maplibregl.Map | undefined = undefined;
let directions: MapLibreGlDirections | undefined = undefined;
let mapRef: HTMLElement;
let map: maplibregl.Map;
let directions: MapLibreGlDirections;
let interactive = true;
let hoverable = false;
let routeSwitch = false;
Expand Down Expand Up @@ -47,7 +47,7 @@
});
});
let message;
let message: string;
$: if (directions) {
if (directions.hoverable !== hoverable) {
Expand All @@ -61,7 +61,7 @@
}
directions.on("fetchroutesend", (event) => {
if (event.data.code !== "Ok") {
if (event.data && event.data.code !== "Ok") {
message = `${event.data.code}: ${event.data.message ?? "no details available."}`;
} else {
message = "";
Expand Down
8 changes: 4 additions & 4 deletions demo/src/examples/10 Bearings Support and Control.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
type BearingsControlConfiguration,
} from "@maplibre/maplibre-gl-directions";
const meta = examples.find((example) => example.path === $location);
const meta = examples.find((example) => example.path === $location)!;
let mapRef: HTMLElement | undefined = undefined;
let map: Map | undefined = undefined;
let directions: MapLibreGlDirections | undefined = undefined;
let mapRef: HTMLElement;
let map: Map;
let directions: MapLibreGlDirections;
onMount(() => {
map = new maplibregl.Map({
Expand Down
14 changes: 7 additions & 7 deletions demo/src/examples/11 Restyling.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import balloonHoverpointImgUrl from "../assets/map/images/balloon-hoverpoint.png?url";
import routelineImgUrl from "../assets/map/images/routeline.png?url";
const meta = examples.find((example) => example.path === $location);
const meta = examples.find((example) => example.path === $location)!;
let mapRef: HTMLElement | undefined = undefined;
let directions: MapLibreGlDirections | undefined = undefined;
let mapRef: HTMLElement;
let directions: MapLibreGlDirections;
onMount(() => {
const map = new maplibregl.Map({
Expand All @@ -33,22 +33,22 @@
// make sure to load and add the images used by the custom directions' styles first:
// a balloon for thw waypoints,
map.loadImage(balloonWaypointImgUrl, (error, image) => {
if (!error) map.addImage("balloon-waypoint", image);
if (!error && image) map.addImage("balloon-waypoint", image);
});
// a balloon for the snappoints,
map.loadImage(balloonSnappointImgUrl, (error, image) => {
if (!error) map.addImage("balloon-snappoint", image);
if (!error && image) map.addImage("balloon-snappoint", image);
});
// a balloon for the hoverpoints
map.loadImage(balloonHoverpointImgUrl, (error, image) => {
if (!error) map.addImage("balloon-hoverpoint", image);
if (!error && image) map.addImage("balloon-hoverpoint", image);
});
// and a pattern-image for the routelines.
map.loadImage(routelineImgUrl, (error, image) => {
if (!error) map.addImage("routeline", image);
if (!error && image) map.addImage("routeline", image);
});
directions = new MapLibreGlDirections(map, {
Expand Down
6 changes: 3 additions & 3 deletions demo/src/examples/12 Distance Measurement.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import "maplibre-gl/dist/maplibre-gl.css";
import style from "../assets/map/style/style.json?url";
import DistanceMeasurementMapLibreGlDirections, { config } from "../assets/map/distance-measurement-directions";
const meta = examples.find((example) => example.path === $location);
const meta = examples.find((example) => example.path === $location)!;
let mapRef: HTMLElement | undefined = undefined;
let directions: DistanceMeasurementMapLibreGlDirections | undefined = undefined;
let mapRef: HTMLElement;
let directions: DistanceMeasurementMapLibreGlDirections;
let totalDistance = 0;
Expand Down
12 changes: 6 additions & 6 deletions demo/src/examples/13 Load and Save.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import style from "../assets/map/style/style.json?url";
import CustomMapLibreGlDirections from "../assets/map/custom-directions";
const meta = examples.find((example) => example.path === $location);
const meta = examples.find((example) => example.path === $location)!;
let mapRef: HTMLElement | undefined = undefined;
let directions: CustomMapLibreGlDirections | undefined = undefined;
let mapRef: HTMLElement;
let directions: CustomMapLibreGlDirections;
onMount(() => {
const map = new maplibregl.Map({
Expand Down Expand Up @@ -39,9 +39,9 @@
let noDataToLoad = !checkDataToLoad();
function loadRoute() {
directions.setWaypointsFeatures(JSON.parse(localStorage.getItem("saved-waypoints-features")));
directions.setSnappointsFeatures(JSON.parse(localStorage.getItem("saved-snappoints-features")));
directions.setRoutelinesFeatures(JSON.parse(localStorage.getItem("saved-routelines-features")));
directions.setWaypointsFeatures(JSON.parse(localStorage.getItem("saved-waypoints-features") || ""));
directions.setSnappointsFeatures(JSON.parse(localStorage.getItem("saved-snappoints-features") || ""));
directions.setRoutelinesFeatures(JSON.parse(localStorage.getItem("saved-routelines-features") || ""));
}
function saveRoute() {
Expand Down
12 changes: 6 additions & 6 deletions demo/src/examples/14 Multiple profiles.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import { shuffle } from "lodash";
import { colors } from "src/directions/layers";
const meta = examples.find((example) => example.path === $location);
const meta = examples.find((example) => example.path === $location)!;
let mapRef: HTMLElement | undefined = undefined;
let map: Map | undefined = undefined;
let directions: MapLibreGlDirections | undefined = undefined;
let mapRef: HTMLElement;
let map: Map;
let directions: MapLibreGlDirections;
onMount(() => {
const _map = new maplibregl.Map({
Expand Down Expand Up @@ -53,11 +53,11 @@
foot: colors.routelineFoot,
};
const initialProfiles = ["car", "bike", "car", "car", "foot"];
const initialProfiles: (keyof typeof profileColors)[] = ["car", "bike", "car", "car", "foot"];
let profiles = initialProfiles;
$: displayedProfiles = profiles.reduce((res, profile) => {
$: displayedProfiles = profiles.reduce<typeof profiles>((res, profile) => {
if (res[res.length - 1] !== profile) {
res.push(profile);
}
Expand Down
8 changes: 4 additions & 4 deletions demo/src/examples/2 Programmatical Control.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import style from "../assets/map/style/style.json?url";
import MapLibreGlDirections from "@maplibre/maplibre-gl-directions";
const meta = examples.find((example) => example.path === $location);
const meta = examples.find((example) => example.path === $location)!;
let mapRef: HTMLElement | undefined = undefined;
let map: Map | undefined = undefined;
let directions: MapLibreGlDirections | undefined = undefined;
let mapRef: HTMLElement;
let map: Map;
let directions: MapLibreGlDirections;
onMount(() => {
const _map = new maplibregl.Map({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import style from "../assets/map/style/style.json?url";
import MapLibreGlDirections from "@maplibre/maplibre-gl-directions";
const meta = examples.find((example) => example.path === $location);
const meta = examples.find((example) => example.path === $location)!;
let mapRef: HTMLElement | undefined = undefined;
let map: maplibregl.Map | undefined = undefined;
let directions: MapLibreGlDirections | undefined = undefined;
let mapRef: HTMLElement;
let map: maplibregl.Map;
let directions: MapLibreGlDirections;
let annotations = "congestion";
onMount(() => {
Expand Down
6 changes: 3 additions & 3 deletions demo/src/examples/4 Origin and Destination.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import style from "../assets/map/style/style.json?url";
import MapLibreGlDirections, { layersFactory } from "@maplibre/maplibre-gl-directions";
const meta = examples.find((example) => example.path === $location);
const meta = examples.find((example) => example.path === $location)!;
let mapRef: HTMLElement | undefined = undefined;
let directions: MapLibreGlDirections | undefined = undefined;
let mapRef: HTMLElement;
let directions: MapLibreGlDirections;
onMount(() => {
const map = new maplibregl.Map({
Expand Down
6 changes: 3 additions & 3 deletions demo/src/examples/5 Show Routes' Directions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import MapLibreGlDirections, { layersFactory } from "@maplibre/maplibre-gl-directions";
import DirectionArrowImageUrl from "../assets/map/images/direction-arrow.png?url";
const meta = examples.find((example) => example.path === $location);
const meta = examples.find((example) => example.path === $location)!;
let mapRef: HTMLElement | undefined = undefined;
let directions: MapLibreGlDirections | undefined = undefined;
let mapRef: HTMLElement;
let directions: MapLibreGlDirections;
onMount(() => {
const map = new maplibregl.Map({
Expand Down
8 changes: 4 additions & 4 deletions demo/src/examples/6 Touch-Friendly Features.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import style from "../assets/map/style/style.json?url";
import MapLibreGlDirections, { layersFactory } from "@maplibre/maplibre-gl-directions";
const meta = examples.find((example) => example.path === $location);
const meta = examples.find((example) => example.path === $location)!;
let mapRef: HTMLElement | undefined = undefined;
let map: Map | undefined = undefined;
let directions: MapLibreGlDirections | undefined = undefined;
let mapRef: HTMLElement;
let map: Map;
let directions: MapLibreGlDirections;
// `maxTouchPoints` isn't recognized by TS. Safe to ignore.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Expand Down
6 changes: 3 additions & 3 deletions demo/src/examples/7 Events.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import style from "../assets/map/style/style.json?url";
import MapLibreGlDirections from "@maplibre/maplibre-gl-directions";
const meta = examples.find((example) => example.path === $location);
const meta = examples.find((example) => example.path === $location)!;
let mapRef: HTMLElement | undefined = undefined;
let directions: MapLibreGlDirections | undefined = undefined;
let mapRef: HTMLElement;
let directions: MapLibreGlDirections;
let messages: string[] = [];
onMount(() => {
Expand Down
8 changes: 4 additions & 4 deletions demo/src/examples/8 Aborting Requests.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import style from "../assets/map/style/style.json?url";
import MapLibreGlDirections from "@maplibre/maplibre-gl-directions";
const meta = examples.find((example) => example.path === $location);
const meta = examples.find((example) => example.path === $location)!;
let mapRef: HTMLElement | undefined = undefined;
let map: Map | undefined = undefined;
let directions: MapLibreGlDirections | undefined = undefined;
let mapRef: HTMLElement;
let map: Map;
let directions: MapLibreGlDirections;
let requestTimeout = 1000;
onMount(() => {
Expand Down
8 changes: 4 additions & 4 deletions demo/src/examples/9 Loading Indicator Control.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import style from "../assets/map/style/style.json?url";
import MapLibreGlDirections, { LoadingIndicatorControl } from "@maplibre/maplibre-gl-directions";
const meta = examples.find((example) => example.path === $location);
const meta = examples.find((example) => example.path === $location)!;
let mapRef: HTMLElement | undefined = undefined;
let map: Map | undefined = undefined;
let directions: MapLibreGlDirections | undefined = undefined;
let mapRef: HTMLElement;
let map: Map;
let directions: MapLibreGlDirections;
onMount(() => {
map = new maplibregl.Map({
Expand Down
2 changes: 1 addition & 1 deletion demo/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import App from "./App.svelte";
import "./assets/styles/index.css";

export default new App({
target: document.getElementById("app"),
target: document.getElementById("app")!,
});
5 changes: 3 additions & 2 deletions demo/src/router.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Menu from "./Menu.svelte";
import type { ComponentType } from "svelte";

export const examples = Object.entries(import.meta.glob("./examples/**.svelte", { eager: true })).map(
([path, component]) => {
const parsedFileName = path.match(/\/(\d+)\s([^/]+)\./);
const parsedFileName = path.match(/\/(\d+)\s([^/]+)\./)!;
const index = parseInt(parsedFileName[1]);
const name = parsedFileName[2];

Expand All @@ -16,7 +17,7 @@ export const examples = Object.entries(import.meta.glob("./examples/**.svelte",
},
);

const routes = {};
const routes: Record<string, ComponentType> = {};

examples.forEach((example) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down
15 changes: 7 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
"extends": "@tsconfig/svelte/tsconfig.json",
"compilerOptions": {
"noEmit": true,
"strict": false,
"strict": true,
"target": "esnext",
"useDefineForClassFields": true,
"module": "esnext",
"resolveJsonModule": true,
"baseUrl": ".",
"allowJs": true,
"checkJs": true,
"isolatedModules": true
"isolatedModules": true,
"paths": {
"@placemarkio/polyline": ["node_modules/@placemarkio/polyline/dist/index.d.ts"]
},
"types": []
},
"include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.svelte", "demo/**/*.d.ts", "demo/**/*.ts", "demo/**/*.svelte"],
"references": [
{
"path": "./tsconfig.node.json"
}
]
"include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.svelte", "demo/**/*.d.ts", "demo/**/*.ts", "demo/**/*.svelte"]
}
3 changes: 2 additions & 1 deletion tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"isolatedModules": true,
"paths": {
"@placemarkio/polyline": ["node_modules/@placemarkio/polyline/dist/index.d.ts"]
}
},
"types": []
},
"include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.svelte"],
"references": [
Expand Down

0 comments on commit 402c63d

Please sign in to comment.