Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript Support #16

Open
canpacis opened this issue May 5, 2022 · 3 comments
Open

Typescript Support #16

canpacis opened this issue May 5, 2022 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@canpacis
Copy link

canpacis commented May 5, 2022

At the moment typescript linting tools does not like working with nucleoid. The way I understand this is that when I register a class I get static helper methods on the class in runtime but these do not exist in the code itself, nor their type declarations.

class User {
  constructor(public name: string) {
    this.name = name;
  }
}
nucleoid.register(User);

app.get("/user", () => User.filter(() => /* */));

So something like this will throw an error like Property 'filter' does not exist on type 'typeof User'.

Are you planning to add typescript support?

@canmingir
Copy link
Member

Definitely, I am still vetting couple options, but the best way that I can come with extending the class like this

import nucleoid, { Prototype } from "nucleoidjs";
const app = nucleoid();

class User extends Prototype {
  name: string;

  constructor(name: string) {
    super();
    this.name = name;
  }
}

app.post("/users", () => User.filter((u) => u.name === "Daphne"));

@canmingir
Copy link
Member

The way I understand this is that when I register a class I get static helper methods on the class in runtime but these do not exist in the code itself, nor their type declarations.

That is right, the runtime rerenders JavaScript and creates graph (all of them happens at the runtime tho). It provides some shortcuts like turning class into array in order to query like in database table. Since all of them happening at the runtime, it is quite conflicts with TypeScript, which is compile time.

@canmingir canmingir self-assigned this May 8, 2022
@canmingir canmingir added the enhancement New feature or request label May 8, 2022
@canpacis
Copy link
Author

canpacis commented May 9, 2022

I think an extendible prototype solution would be the cleanest. I would be easy to read and understand, while not clashing with ide's

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants