How to use the typescript-is.assertType function in typescript-is

To help you get started, we’ve selected a few typescript-is examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FreemapSlovakia / freemap-v3-react / src / processors / changesetsProcessor.ts View on Github external
const { data } = await httpRequest({
        getState,
        method: 'GET',
        url: '//api.openstreetmap.org/api/0.6/changesets',
        expectedStatus: [200, 404],
        params: {
          bbox,
          time: fromTime + (toTime0 ? `,${toTime0}` : ''),
          // eslint-disable-next-line
          display_name: state.changesets.authorName,
        },
        cancelActions: [changesetsSetAuthorName, selectFeature, clearMap],
      });

      const xml = new DOMParser().parseFromString(
        assertType(data),
        'text/xml',
      );

      const rawChangesets = xml.getElementsByTagName('changeset');
      const arrayOfrawChangesets = Array.from(rawChangesets);
      const changesetsFromThisRequest = arrayOfrawChangesets
        .map(rawChangeset => {
          const minLat = parseFloat(rawChangeset.getAttribute('min_lat') ?? '');
          const maxLat = parseFloat(rawChangeset.getAttribute('max_lat') ?? '');
          const minLon = parseFloat(rawChangeset.getAttribute('min_lon') ?? '');
          const maxLon = parseFloat(rawChangeset.getAttribute('max_lon') ?? '');

          const descriptionTag = Array.from(
            rawChangeset.getElementsByTagName('tag'),
          ).find(tag => tag.getAttribute('k') === 'comment');
github FreemapSlovakia / freemap-v3-react / src / index.tsx View on Github external
function loadAppState(): void {
  let appState: AppState | undefined;
  const as = storage.getItem('appState');
  if (as) {
    try {
      appState = assertType(JSON.parse(as));
    } catch (e) {
      storage.removeItem('appState');
      throw e;
    }
  }

  if (appState) {
    store.dispatch(setAppState(appState));
  }

  store.dispatch(
    l10nSetChosenLanguage(
      appState?.language?.replace(/-.*/, '') ?? null, // fixing wrong saved language because of bug in older version
    ),
  );
}
github FreemapSlovakia / freemap-v3-react / src / processors / trackViewerSetTrackDataProcessor.ts View on Github external
transform: ({ action }) => {
    if (!action.payload.trackGpx) {
      return action;
    }

    // TODO add error handling for failed string-to-gpx and gpx-to-geojson parsing
    const gpxAsXml = new DOMParser().parseFromString(
      action.payload.trackGpx,
      'text/xml',
    );

    const trackGeojson = assertType(toGeoJSON.gpx(gpxAsXml));

    const startPoints: TrackPoint[] = []; // TODO
    const finishPoints: TrackPoint[] = []; // TODO

    for (const feature of trackGeojson.features) {
      if (feature.geometry.type === 'LineString') {
        const lengthInKm = turfLength(feature);
        const coords = feature.geometry.coordinates;
        const startLonlat = coords[0];
        let startTime: Date | undefined;
        let finishTime: Date | undefined;
        const times = assertType(
          feature.properties && feature.properties.coordTimes,
        );
        if (times) {
          startTime = new Date(times[0]);
github FreemapSlovakia / freemap-v3-react / src / processors / galleryFetchUsersProcessor.ts View on Github external
handle: async ({ getState, dispatch }) => {
    const { data } = await httpRequest({
      getState,
      method: 'GET',
      url: '/gallery/picture-users',
      expectedStatus: 200,
    });

    dispatch(gallerySetUsers(assertType(data)));
  },
};
github FreemapSlovakia / freemap-v3-react / src / processors / authLoginWithFacebookProcessor.ts View on Github external
if (response.status !== 'connected') {
        dispatch(toastsAddError('logIn.logInError2'));
        return;
      }
    }

    const { data } = await httpRequest({
      getState,
      method: 'POST',
      url: `/auth/login-fb`,
      cancelActions: [],
      expectedStatus: 200,
      data: { accessToken: response.authResponse.accessToken },
    });

    const user = assertType(data);

    dispatch(
      toastsAdd({
        collapseKey: 'login',
        messageKey: 'logIn.success',
        style: 'info',
        timeout: 5000,
      }),
    );

    dispatch(authSetUser(user));
  },
};
github FreemapSlovakia / freemap-v3-react / src / coordinatesParser.ts View on Github external
function toLatLon(
  coord1deg: number,
  coord1min: number,
  coord1sec: number,
  card1: string,
  coord2deg: number,
  coord2min: number,
  coord2sec: number,
  card2: string,
): LatLon {
  const latLon = {
    ...toLatLon1(coord1deg, coord1min, coord1sec, card1),
    ...toLatLon1(coord2deg, coord2min, coord2sec, card2),
  };
  return assertType(latLon);
}
github FreemapSlovakia / freemap-v3-react / src / coordinatesParser.ts View on Github external
export function parseCoordinates(coord: string): LatLon {
  const mXml = P_XML.exec(coord);
  if (mXml) {
    return assertType({
      ...toLatLon1(parseFloat(mXml[1].replace(',', '.')), 0.0, 0.0, 'N'),
      ...toLatLon1(parseFloat(mXml[2].replace(',', '.')), 0.0, 0.0, 'E'),
    });
  }

  const sb: string[] = [];
  const list: Array = [];

  const P = new RegExp(patterns, 'ig');

  for (let i = 0; i < 100; i += 1) {
    const m = P.exec(coord);
    if (!m) {
      break;
    }
github FreemapSlovakia / freemap-v3-react / src / processors / routePlannerFindRouteProcessor.ts View on Github external
const alts = rts.map((rt: any) => {
        const route = assertType(rt);

        const {
          legs,
          distance: totalDistance,
          duration: totalDuration,
          extra: totalExtra,
        } = route;

        const itinerary = ([] as any).concat(
          ...legs.map((leg, legIndex: number) =>
            leg.steps.map(
              ({
                name,
                distance,
                duration,
                mode: m,
github FreemapSlovakia / freemap-v3-react / src / processors / elevationMeasurementProcessor.ts View on Github external
if (!point) {
      dispatch(elevationMeasurementSetElevation(null));
      return;
    }

    const { data } = await httpRequest({
      getState,
      method: 'GET',
      url: '/geotools/elevation',
      params: {
        coordinates: `${point.lat},${point.lon}`,
      },
      cancelActions: [elevationMeasurementSetPoint, clearMap],
    });

    dispatch(elevationMeasurementSetElevation(assertType<[number]>(data)[0]));
  },
};

typescript-is

TypeScript transformer that generates run-time type-checks.

MIT
Latest version published 1 year ago

Package Health Score

54 / 100
Full package analysis

Popular typescript-is functions