openrouteservice-js icon indicating copy to clipboard operation
openrouteservice-js copied to clipboard

TypeScript support

Open Splicer97 opened this issue 3 years ago • 4 comments

How about implement typescript support for your package?

Splicer97 avatar Nov 10 '22 15:11 Splicer97

Would be awesome, but currently not in our scope, as i don't have any experience with it, yet... Feel free to contribute with a PR though!

TheGreatRefrigerator avatar Nov 14 '22 09:11 TheGreatRefrigerator

Hello,

I use a AWS lambda with a runtime Node.js 14. I tried to import openrouteservice-js.

But when I try to run my code the following error appears :

{
    "errorType": "TypeError",
    "errorMessage": "o is not a function",
    "stack": [
        "TypeError: o is not a function",....
}

Here what I've done:

mylambda.ts :

import Openrouteservice from "openrouteservice-js";

.....
exports.generateGpxHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {
    const { httpMethod, body, headers } = event;
....

// the line causing error
    const directionsService = new Openrouteservice.Directions({ api_key: OPENROUTE_API_KEY });
.............

}

I declare a types.d.ts file :

declare module "openrouteservice-js";

in my package.json :


"dependencies": {
        "aws-sdk": "^2.1238.0",
        "@aws-sdk/client-dynamodb": "3.194.0",
        "@aws-sdk/lib-dynamodb": "3.194.0",
        "jwt-decode": "3.1.2",
        "uuid": "9.0.0",
        "openrouteservice-js": "0.2.0"
    },

my tsconfig.json:


{
  "compilerOptions": {
    "target": "ES6",
    "moduleResolution": "node",
    "noImplicitAny": true,
    "preserveConstEnums": true,
    "outDir": "./bin",
    "sourceMap": true
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}

I also use a webpack.conf.js file similar to my open source project:

https://github.com/Basile001/another-aws-example/blob/master/back/webpack.config.js

I don't understand why my lambda return this error, I miss something but I don't know what it is ?

I tried the require way instead of the import way but the result is the same, or to mess up with my tsconfig file but nothing change.

Thank you for the help in advance.

Kind regards,

Basile

Basile001 avatar Dec 16 '22 08:12 Basile001

Perhaps this can be used to generate the TypeScript declaration file(s).

https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html

didierdemaeyer avatar Oct 22 '23 22:10 didierdemaeyer

@TheGreatRefrigerator how about https://github.com/brianhvo02/openrouteservice-api ? I think @brianhvo02 has done a very good job that you can use as a base. Typescript is very important nowadays

fraction01 avatar Apr 18 '25 10:04 fraction01