Can't build agent-nodejs with TypeScript

Hi,

My name is Bruno, I’m the CTO of Offishall [ www.offishall.io ]

I can’t build my server with agent-nodejs with TypeScript.
I use express and SQL, no Mongoose or Sequelize.

I don’t use koa, but I had to install “@types/koa__router”, why ?

I wrote a very simple express server to test everything. Just copying code from your example.
I try to build it with tsc. Here is my tsconfig.json:

{
  "compilerOptions": {
    "target": "es2019",
    "module": "commonjs",
    "outDir": "./dist",
    "baseUrl": ".",
    "strict": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "useUnknownInCatchVariables": false,
    "paths": {
      "~/*": ["src/*"],
    },
  }
}

Errors are:

node_modules/@forestadmin/datasource-customizer/dist/decorators/validation/collection.d.ts:3:58 - error TS2537: Type '{ operator: "Equal" | "NotEqual" | "LessThan" | "GreaterThan" | "Like" | "ILike" | "NotContains" | "LongerThan" | "ShorterThan" | "IncludesAll" | "Today" | "Yesterday" | "PreviousMonth" | ... 25 more ... | "Past"; value?: unknown; }[] | undefined' has no matching index signature for type 'number'.

3 declare type ValidationRule = ColumnSchema['validation'][number];
                                                           ~~~~~~

node_modules/@forestadmin/datasource-sql/dist/introspection/types.d.ts:2:87 - error TS2537: Type '{}' has no matching index signature for type 'number'.

2 export declare type SequelizeIndex = Awaited<ReturnType<QueryInterface['showIndex']>>[number];
                                                                                        ~~~~~~

node_modules/@forestadmin/datasource-sql/dist/introspection/types.d.ts:5:113 - error TS2537: Type '{}' has no matching index signature for type 'number'.

5 export declare type SequelizeReference = Awaited<ReturnType<QueryInterface['getForeignKeyReferencesForTable']>>[number];

This looks very promising though. Thanks for the help !

Bruno

Hi @brunorzn, and welcome to our community :wave:

I can’t build my server with agent-nodejs with TypeScript.
I use express and SQL, no Mongoose or Sequelize.

Could you also share the name of the associated project?

I don’t use koa, but I had to install “@types/koa__router”, why ?

Did you get an error related to the requirement of @types/koa__router? If so, would you mind share the stacktrace?

We use Koa internally, but manually installing @types/koa__router shouldn’t be required in your project.

For your error, adding

"skipLibCheck": true

to your typescript config should prevent this error, or you can simply call tsc --skipLibCheck.

As a side note (and if you don’t need express in your project), you can also run the agent as a standalone process, as shown in this quick start documentation.

Let me know if that helps :pray:

Hi @jeffladiray

Thank you for your quick answer !

TL;DR

Adding @types/koa__router and skipLibCheck to true did the trick.


Here is the stack trace for the @types/koa__router

node_modules/@forestadmin/agent/dist/framework-mounter.d.ts:1:23 - error TS2688: Cannot find type definition file for 'koa__router'.

1 /// <reference types="koa__router" />
                        ~~~~~~~~~~~

node_modules/@forestadmin/agent/dist/framework-mounter.d.ts:3:20 - error TS7016: Could not find a declaration file for module '@koa/router'. '/Users/bruno/dev/offishall/server/node_modules/@koa/router/lib/router.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/koa__router` if it exists or add a new declaration (.d.ts) file containing `declare module '@koa/router';`

3 import Router from '@koa/router';
                     ~~~~~~~~~~~~~

I do want to use Express and Typescript so I can reuse a lot of things from our existing codebase which is what I was lacking a year ago or so. Dev experience seems to be a lot better now :slight_smile:

I don’t really mind adding the koa types but it’s not very clean :slight_smile:

I’ve added the skipLikCheck for now and the build is okay.

Thank you!

1 Like

I do want to use Express and Typescript so I can reuse a lot of things from our existing codebase which is what I was lacking a year ago or so. Dev experience seems to be a lot better now :slight_smile:

This was one of the main goal of this new agent (Along with a lot of new features) :smiley:

w’ll take a look to see if we are able to reproduce this issue with koa__router on our end (Since it should definitely not be required) and we’ll let you know.

Thanks for your response :pray: