Skip to content

OpenLayers 5+ TypeScript declaration

License

Notifications You must be signed in to change notification settings

JakeTunaley/types-ol

 
 

Repository files navigation

Build Status npm version

OpenLayers TypeScript Definition

Definitions from this project will be syncronized with official @types/ol package.

This project contains TypeScript definition for OpenLayers v6.1.1 that includes all documented API and protected class members and methods. Check v5.3.x branch for OpenLayers v5.3.x definitions.

OpenLayers v6 Progress

TODO

  • Fix Generic Types

Installation

Official package (recommended)

# NPM
npm i -D @types/ol

# Yarn
yarn add -D @types/ol

This project package

# NPM
npm i -D @hanreev/types-ol

# Yarn
yarn add -D @hanreev/types-ol

Usage

There are several ways to use this package. Please choose one:

  • Install as @types/ol. This will simulate @types/ol installation from node_modules/@hanreev/types-ol/ol directory.
    Why?

    • TypeScript compiler will look for types in node_modules/@types by default.
    • If you're using Visual Studio Code, its IntelliSense will only recognize types from node_modules/@types.
    // file: package.json
    
    {
      ...
      "devDependencies": {
        ...
        "@hanreev/types-ol": "^3.1.1",
        "@types/ol": "file:node_modules/@hanreev/types-ol/ol",
        ...
      }
    }

    then run

    # NPM
    npm i
    
    # Yarn
    yarn install

    Note:
    This package must be installed first before adding "@types/ol": "file:node_modules/@hanreev/types-ol/ol" in package.json.

  • Using compilerOptions.paths in tsconfig.json

    // file: tsconfig.json
    
    {
      "compilerOptions": {
        ...
        "baseUrl": "./",
        "paths": {
          "ol": ["node_modules/@hanreev/types-ol/ol"],
          "ol/*": ["node_modules/@hanreev/types-ol/ol/*"]
        },
        ...
      }
    }

Configuring and Building TypeScript definition files

Configuration is located at jsdoc/conf.json

// file: jsdoc/conf.json

{
  "source": {
    ...
    "include": [
      "openlayers/src/ol" // openlayers source
    ]
  },
  ...
  "typescript": {
    "moduleRoot": "openlayers/src", // openlayers source
    "declaration": {
      "extraOptions": true, // BaseObject derivatives can accept extra properties.
      "mode": "multiple", // "single" will generate all declarations in single index.d.ts file.
      "strictGenericTypes": false // set to true to extract classes generic type from super class, members and methods.
      "strictReturnTypes": false // set to true to include undefined and null return.
    }
  },
  ...
}
  • Install all dependencies

    # NPM
    npm i
    
    # Yarn
    yarn install
  • Run build

    # NPM
    npm run build-format && npm run lint
    
    # Yarn
    yarn build-format && yarn lint
  • Run test

    # NPM
    npm run lint-test && npm run test
    
    # Yarn
    yarn lint-test && yarn test

Note:
Some definition was patched manually. If you found any error please create a new issue.

Changelog

  • v3.1.1
    • Set opt_options constructor parameter of ol/source/IIIF~IIIF as optional.
    • ol/Object~BaseObject derived classes can accept extra options.
    • Change ol/size.Size type from number[] to [number, number]
  • v3.1.0
  • v3.0.0
    • OpenLayers v6
  • v2.0.8
    • nullable parameter types
    • fix ol/Feature.setStyle and ol/layer/Vector.setStyle
  • v2.0.7
    • Add unified undefined parameter type--e.g., ol/Overlay~Overlay#setPosition method can accept either coordinate or undefined
  • v2.0.6
    • Fix external import with same member name--e.g., GeoJSON from geojson module in ol/format/GeoJSON
    • Order module members by kind
  • v2.0.5
    • Fix anonymous function parameters type
    • Fix union types
  • v2.0.4
    • Fix optional parameters in function type--e.g., third parameter of {function(*, Array<*>, string=): (Node|undefined)}
    • Test files fixes
  • v2.0.3
    • OpenLayers 5.3.3 source
    • Members and methods sorting
  • v2.0.2
    • Fix object type
    • Use relative import path for ol modules (no-self-import)
  • v2.0.1
    • Refactor definition filenames
    • Remove module declaration (no-declare-current-package)
    • DefinitelyTyped standard. These dtslint rules are ignored:
      • adjacent-overload-signatures
      • array-type
      • max-line-length
      • no-self-import
      • no-unnecessary-class
      • no-unnecessary-generics
      • unified-signatures
  • v1.0.2
    • Sort imports
    • NPM compatibility as @types/ol
  • v1.0.1
    • Fix ol/MapBrowserEventType module
  • v1.0.0
    • Initial release

License

Copyright © 2019 Rifa'i M. Hanif
Licensed under MIT License

About

OpenLayers 5+ TypeScript declaration

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 84.0%
  • JavaScript 16.0%