import distance from '@turf/distance';
import { segmentReduce } from '@turf/meta';
import { Feature, FeatureCollection, LineString, MultiLineString, GeometryCollection, Units } from '@turf/helpers';

/**
 * Takes a {@link GeoJSON} and measures its length in the specified units, {@link (Multi)Point}'s distance are ignored.
 *
 * @name length
 * @param {Feature<LineString|MultiLineString>} geojson GeoJSON to measure
 * @param {Object} [options={}] Optional parameters
 * @param {string} [options.units=kilometers] can be degrees, radians, miles, or kilometers
 * @returns {number} length of GeoJSON
 * @example
 * var line = turf.lineString([[115, -32], [131, -22], [143, -25], [150, -34]]);
 * var length = turf.length(line, {units: 'miles'});
 *
 * //addToMap
 * var addToMap = [line];
 * line.properties.distance = length;
 */
export default function length(geojson: Feature<any> | FeatureCollection<any> | GeometryCollection, options: {
    units?: Units
} = {}): number {
    // Calculate distance from 2-vertex line segments
    return segmentReduce(geojson, (previousValue, segment) => {
        const coords = segment!.geometry.coordinates;
        return previousValue! + distance(coords[0], coords[1], options);
    }, 0);
}

import distance from '@turf/distance';
import { segmentReduce } from '@turf/meta';
import { Feature, FeatureCollection, LineString, MultiLineString, GeometryCollection, Units } from '@turf/helpers';

/**
 * Takes a {@link GeoJSON} and measures its length in the specified units, {@link (Multi)Point}'s distance are ignored.
 *
 * @name length
 * @param {Feature<LineString|MultiLineString>} geojson GeoJSON to measure
 * @param {Object} [options={}] Optional parameters
 * @param {string} [options.units=kilometers] can be degrees, radians, miles, or kilometers
 * @returns {number} length of GeoJSON
 * @example
 * var line = turf.lineString([[115, -32], [131, -22], [143, -25], [150, -34]]);
 * var length = turf.length(line, {units: 'miles'});
 *
 * //addToMap
 * var addToMap = [line];
 * line.properties.distance = length;
 */
export default function length(geojson: Feature<any> | FeatureCollection<any> | GeometryCollection, options: {
    units?: Units
} = {}): number {
    // Calculate distance from 2-vertex line segements
    return segmentReduce(geojson, function (previousValue, segment) {
        var coords = segment.geometry.coordinates;
        return previousValue + distance(coords[0], coords[1], options);
    }, 0);
}

--- 
+++ 
@@ -21,9 +21,9 @@
 export default function length(geojson: Feature<any> | FeatureCollection<any> | GeometryCollection, options: {
     units?: Units
 } = {}): number {
-    // Calculate distance from 2-vertex line segements
-    return segmentReduce(geojson, function (previousValue, segment) {
-        var coords = segment.geometry.coordinates;
-        return previousValue + distance(coords[0], coords[1], options);
+    // Calculate distance from 2-vertex line segments
+    return segmentReduce(geojson, (previousValue, segment) => {
+        const coords = segment!.geometry.coordinates;
+        return previousValue! + distance(coords[0], coords[1], options);
     }, 0);
 }
Refactor length-function for TypeScript strict mode and some other minor enhancements.
