Answer the question
In order to leave comments, you need to log in
How to return a class from a function?
The function substitutes values into the class, but there are problems with the return.
Error: Return type of exported function has or is using private name 'EntityClass'.
import {Entity, PrimaryColumn, Column} from "typeorm";
export function createEntity(tableName: string) {
@Entity({name: tableName})
class EntityClass {
public static tableName = tableName;
@PrimaryColumn()
public name: string = "";
@Column()
public value: number = 0;
}
return EntityClass;
}
Answer the question
In order to leave comments, you need to log in
Take the class out of the function and export it too
@Entity({name: tableName})
export class EntityClass {
public static tableName = tableName;
@PrimaryColumn()
public name: string = "";
@Column()
public value: number = 0;
}
export function createEntity(tableName: string) {
return EntityClass;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question