deepkit / deepkit-framework

A new full-featured and high-performance TypeScript framework
https://deepkit.io/
MIT License
3.14k stars 116 forks source link

[Bug] Debugger Fails to Work in a Particular Case #241

Open Char2sGu opened 2 years ago

Char2sGu commented 2 years ago

It happens only when:

import { App } from "@deepkit/app";
import { FrameworkModule } from "@deepkit/framework";
import { Database, MemoryDatabaseAdapter } from "@deepkit/orm";

class Entity<T = never> {}
class MyEntity extends Entity<unknown> {} // works when no generic type argument is passed: `extends Entity`

// workaround for the bug that `Database` cannot be used as a token
class DatabaseToken extends Database {}

new App({
  imports: [new FrameworkModule({ debug: true })],
  providers: [
    {
      provide: DatabaseToken, // works when the token is not a class extending `Database`
      useValue: new Database(new MemoryDatabaseAdapter(), [MyEntity]),
    },
  ],
}).run();

If all the requirements are met, the debugger will fail to work and report a lot of errors:

image

Char2sGu commented 2 years ago

FrameworkModule detects databases by tokens, and the debugger replies on the detected databases, which is the reason of why the issue disappears when providing databases using other tokens.

        if (isPrototypeOfBase(token, Database)) {
            this.dbs.push({ classType: token as ClassType, module });
        }