arangodb/arangojs

7.6.0 Type Annotation for DocumentCollection

denny99 opened this issue · 8 comments

Version 7.6.0 introduced a new type defintion for the collection generic.

Was:
DocumentCollection<T extends object = any>

Is now:

DocumentCollection<T extends Record<string, unknown>>

The Record type with unknown forces me to give all of my interfaces an index signature like [key: string]: unknown.
As soon as i start adding the signature a whole lot of other things start to break... And obviously it is not correct, i don't want foreign fields on my objects.

So right now, it is just impossible for us to upgrade, so i had to freeze my version back to 7.5.0.

I know object and any are discouraged. But a Record<string, any> doesn't force us to always use index signatures.
So this might be a better solution for replacing object?

image
image

pluma commented

Ah, crap. I thought I had reverted the breaking type changes. I'll have to investigate and maybe do a bugfix release to address this.

pluma commented

You shouldn't need to extend/implement Record explicitly. A regular object should satisfy this type.

This seems to work for me:

interface Coordinates {
  x: number;
  y: number;
}
const col = db.collection("coords") as DocumentCollection<Coordinates>;

image

for me it's not. i am not using an interface, i am using a class here

image

An interface doesn't work neither

We have really really strict settings for typescript for maximum performance. So it might be related to that?

pluma commented

@denny99 can you attach your tsconfig so I can try to figure out what's going on?

Sure

{
  "compilerOptions": {
    "strict": true,
    "noImplicitAny": false,
    "strictNullChecks": false,
    "module": "CommonJS",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "declarationMap": true,
    "resolveJsonModule": true,
    "moduleResolution": "Node",
    "target": "ES2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "typeRoots": [
      "node_modules/@types",
      "../node_modules/@types",
      "../types"
    ]
  }
}

And we are running on typescript "typescript": "^4.4.2"

pluma commented

Fixed via 0e8bad0.