appy-one / acebase

A fast, low memory, transactional, index & query enabled NoSQL database engine and server for node.js and browser with realtime data change notifications
MIT License
481 stars 27 forks source link

Multiple TypeScript errors when using package acebase #220

Closed Septh closed 1 year ago

Septh commented 1 year ago

This minimalist TypeScript code:

import { AceBase } from 'acebase'

ends up with TypeScript reporting 6 errors.

(expand to reveal screenshot, text-only version is below) ![image](https://user-images.githubusercontent.com/11949623/234641960-28935cb0-3e72-4bd7-a1a1-baed93cacea0.png)
Stephan@Bombasse-III MINGW64 ~/Dev/zz_tests/acebase
$ tsc
node_modules/acebase/dist/types/storage/binary/index.d.ts:267:5 - error TS2416: Property 'getChildren' in type 'AceBaseStorage' is not assignable to the same property in base type 'Storage'.
  Type '(path: string, options?: { keyFilter?: string[] | number[] | undefined; tid?: string | number | undefined; async?: boolean | undefined; } | undefined) => { next(valueCallback: (child: BinaryNodeInfo) => boolean | void, useAsync?: boolean | undefined): Promise<...>; }' is not assignable to type '(path: string, options?: { keyFilter?: string[] | number[] | undefined; tid?: string | number | undefined; async?: boolean | undefined; } | undefined) => { next: (callback: (child: NodeInfo) => boolean | ... 1 more ... | Promise<...>) => Promise<...>; }'.
    Call signature return types '{ next(valueCallback: (child: BinaryNodeInfo) => boolean | void, useAsync?: boolean | undefined): Promise<boolean>; }' and '{ next: (callback: (child: NodeInfo) => boolean | void | Promise<boolean | void>) => Promise<boolean>; }' are incompatible.
      The types of 'next' are incompatible between these types.
        Types of parameters 'valueCallback' and 'callback' are incompatible.
          Type 'boolean | void | Promise<boolean | void>' is not assignable to type 'boolean | void'.
            Type 'Promise<boolean | void>' is not assignable to type 'boolean | void'.

267     getChildren(path: string, options?: {
        ~~~~~~~~~~~

node_modules/acebase/dist/types/storage/custom/index.d.ts:187:5 - error TS2416: Property 'getChildren' in type 'CustomStorage' is not assignable to the same property in base type 'Storage'.
  Type '(path: string, options?: { transaction?: CustomStorageTransaction | undefined; keyFilter?: string[] | number[] | undefined; } | undefined) => { next(valueCallback: (child: NodeInfo) => boolean): Promise<...>; }' is not assignable to type '(path: string, options?: { keyFilter?: string[] | number[] | undefined; tid?: string | number | undefined; async?: boolean | undefined; } | undefined) => { next: (callback: (child: NodeInfo) => boolean | ... 1 more ... | Promise<...>) => Promise<...>; }'.
    Call signature return types '{ next(valueCallback: (child: NodeInfo) => boolean): Promise<boolean>; }' and '{ next:(callback: (child: NodeInfo) => boolean | void | Promise<boolean | void>) => Promise<boolean>; }' are incompatible.
      The types of 'next' are incompatible between these types.
        Types of parameters 'valueCallback' and 'callback' are incompatible.
          Type 'boolean | void | Promise<boolean | void>' is not assignable to type 'boolean'.
            Type 'void' is not assignable to type 'boolean'.

187     getChildren(path: string, options?: {
        ~~~~~~~~~~~

node_modules/acebase/dist/types/storage/custom/local-storage/transaction.d.ts:23:5 - error TS2416: Property 'childrenOf' in type 'LocalStorageTransaction' is not assignable to the same property in base type 'CustomStorageTransaction'.
  Type '(path: string, include: { metadata?: boolean | undefined; value?: boolean | undefined; }, checkCallback: (path:string) => boolean, addCallback: (path: string, node: ICustomStorageNodeMetaData | ICustomStorageNode) => boolean) => Promise<...>' is not assignable to type '(path: string, include: { metadata: boolean; value: boolean; }, checkCallback: (childPath: string) => boolean, addCallback?: ((childPath: string, node?: ICustomStorageNodeMetaData | ICustomStorageNode| undefined) => boolean) | undefined) => Promise<...>'.
    Types of parameters 'addCallback' and 'addCallback' are incompatible.
      Type '((childPath: string, node?: ICustomStorageNodeMetaData | ICustomStorageNode | undefined) => boolean) | undefined' is not assignable to type '(path: string, node: ICustomStorageNodeMetaData | ICustomStorageNode) => boolean'.
        Type 'undefined' is not assignable to type '(path: string, node: ICustomStorageNodeMetaData | ICustomStorageNode) => boolean'.

23     childrenOf(path: string, include: {
       ~~~~~~~~~~

node_modules/acebase/dist/types/storage/custom/local-storage/transaction.d.ts:27:5 - error TS2416: Property 'descendantsOf' in type 'LocalStorageTransaction' is not assignable to the same property in base type 'CustomStorageTransaction'.
  Type '(path: string, include: { metadata?: boolean | undefined; value?: boolean | undefined; }, checkCallback: (path:string) => boolean, addCallback: (path: string, node: ICustomStorageNodeMetaData | ICustomStorageNode) => boolean) => Promise<...>' is not assignable to type '(path: string, include: { metadata: boolean; value: boolean; }, checkCallback: (descPath: string, metadata?: ICustomStorageNodeMetaData | undefined) => boolean, addCallback?: ((descPath: string, node?: ICustomStorageNodeMetaData | ... 1 more ... | undefined) => boolean) | undefined) => Promise<...>'.
    Types of parameters 'addCallback' and 'addCallback' are incompatible.
      Type '((descPath: string, node?: ICustomStorageNodeMetaData | ICustomStorageNode | undefined) => boolean) | undefined' is not assignable to type '(path: string, node: ICustomStorageNodeMetaData | ICustomStorageNode) => boolean'.
        Type 'undefined' is not assignable to type '(path: string, node: ICustomStorageNodeMetaData | ICustomStorageNode) => boolean'.

27     descendantsOf(path: string, include: {
       ~~~~~~~~~~~~~

node_modules/acebase/dist/types/storage/mssql/index.d.ts:138:5 - error TS2416: Property 'getChildren' in type 'MSSQLStorage' is not assignable to the same property in base type 'Storage'.
  Type '(path: string, options?: { keyFilter?: (string | number)[] | undefined; tid?: string | number | undefined; } | undefined) => { next(valueCallback: (child: MSSQLNodeInfo) => boolean): Promise<...>; }' is not assignable to type '(path: string, options?: { keyFilter?: string[] | number[] | undefined; tid?: string | number | undefined; async?: boolean |undefined; } | undefined) => { next: (callback: (child: NodeInfo) => boolean | ... 1 more ... | Promise<...>) => Promise<...>; }'.
    Call signature return types '{ next(valueCallback: (child: MSSQLNodeInfo) => boolean): Promise<boolean>; }' and '{ next: (callback: (child: NodeInfo) => boolean | void | Promise<boolean | void>) => Promise<boolean>; }' are incompatible.
      The types of 'next' are incompatible between these types.
        Types of parameters 'valueCallback' and 'callback' are incompatible.
          Type 'boolean | void | Promise<boolean | void>' is not assignable to type 'boolean'.

138     getChildren(path: string, options?: {
        ~~~~~~~~~~~

node_modules/acebase/dist/types/storage/sqlite/index.d.ts:70:5 - error TS2416: Property 'getChildren' in type 'SQLiteStorage' is not assignable to the same property in base type 'Storage'.
  Type '(path: string, options?: { keyFilter?: (string | number)[] | undefined; tid?: string | number | undefined; } | undefined) => { next(valueCallback: (child: SQLiteNodeInfo) => boolean): Promise<...>; }' is not assignable to type '(path: string, options?: { keyFilter?: string[] | number[] | undefined; tid?: string | number | undefined; async?: boolean | undefined; } | undefined) => { next: (callback: (child: NodeInfo) => boolean | ... 1 more ... | Promise<...>) => Promise<...>; }'.
    Call signature return types '{ next(valueCallback: (child: SQLiteNodeInfo) => boolean): Promise<boolean>; }' and '{next: (callback: (child: NodeInfo) => boolean | void | Promise<boolean | void>) => Promise<boolean>; }' are incompatible.
      The types of 'next' are incompatible between these types.
        Types of parameters 'valueCallback' and 'callback' are incompatible.
          Type 'boolean | void | Promise<boolean | void>' is not assignable to type 'boolean'.

70     getChildren(path: string, options?: {
       ~~~~~~~~~~~

Found 6 errors in 5 files.

Errors  Files
     1  node_modules/acebase/dist/types/storage/binary/index.d.ts:267
     1  node_modules/acebase/dist/types/storage/custom/index.d.ts:187
     2  node_modules/acebase/dist/types/storage/custom/local-storage/transaction.d.ts:23
     1  node_modules/acebase/dist/types/storage/mssql/index.d.ts:138
     1  node_modules/acebase/dist/types/storage/sqlite/index.d.ts:70

Stephan@Bombasse-III MINGW64 ~/Dev/zz_tests/acebase
$

AceBase 1.28.2, tested with both TypeScript 4.9.5 and 5.0.4 (note that I have "skipLibCheck": false in tconfig.json).

appy-one commented 1 year ago

Hi @Septh I tried to reproduce but can only when setting skipLibCheck to false. Check out the following minimal project:

package.json:

{
  "name": "issue220",
  "version": "1.0.0",
  "main": "dist/index.js",
  "dependencies": {
    "acebase": "^1.28.2"
  },
  "devDependencies": {
    "typescript": "^5.0.4"
  }
}

tsconfig.json:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "nodenext",
    "rootDir": "./src",
    "outDir": "./dist",
    "esModuleInterop": false,
    "strict": true,
    "skipLibCheck": true
  }
}

src/index.ts:

import { AceBase } from "acebase";

Running npx tsc yields no errors. Setting skipLibCheck to false will yield the errors you posted. I will take a look at the errors, because they should not be there in the first place, but it does look like there is something wrong with your configuration. Are you sure tsc is picking up your tsconfig.json? You did mention tconfig.json, which might a typo or misspelling of the actual file?

Septh commented 1 year ago

Thanks. You're right of course, this is a typo from me - I did mean tsconfig.json. And yes, the errors only show when skipLibCheck is false (which is the default anyway).

appy-one commented 1 year ago

Updating to v1.28.4 should fix this!

Sponsor AceBase Spread the word contribute