TypeScript support
Splicer97 opened this issue · 3 comments
How about implement typescript support for your package?
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!
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
Perhaps this can be used to generate the TypeScript declaration file(s).
https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html