使用 TypeORM 的具体 table 继承 - 编译因抽象关键字而失败
Concrete table inheritance with TypeORM - compilation fails with abstract keyword
我希望有人能帮助我 class 关于 TypeORM 的继承。现在我正在尝试实现具体的 table 继承(我在这里找到:https://github.com/typeorm/typeorm/blob/master/docs/entity-inheritance.md#concrete-table-inheritance),但我看到了这个:
{ SyntaxError: .../src/entities/User.js: Unexpected
token (3:16)
1 | import { PrimaryGeneratedColumn, Column } from 'typeorm';
2 |
> 3 | export abstract class User {
| ^
4 | @PrimaryGeneratedColumn('uuid')
5 | id = undefined;
我猜是因为我的 babel 配置错误或不完整。如果有帮助,我大致按照我在这里找到的内容进行操作:https://github.com/typeorm/babel-example。
产生错误的命令是 $ ./node_modules/.bin/babel-node ./node_modules/.bin/typeorm schema:drop
(已编辑)
您使用的示例存储库用于 JavaScript 代码,而不是 TypeScript。如果您想将它与 TypeScript 代码一起使用,您可以尝试在 .babelrc
中启用 transform-typescript
插件,但最好使用 here 中的 TypeScript 示例之一。或者,只需删除 abstract
。 (abstract
是 TypeScript 独有的功能。)
我希望有人能帮助我 class 关于 TypeORM 的继承。现在我正在尝试实现具体的 table 继承(我在这里找到:https://github.com/typeorm/typeorm/blob/master/docs/entity-inheritance.md#concrete-table-inheritance),但我看到了这个:
{ SyntaxError: .../src/entities/User.js: Unexpected
token (3:16)
1 | import { PrimaryGeneratedColumn, Column } from 'typeorm';
2 |
> 3 | export abstract class User {
| ^
4 | @PrimaryGeneratedColumn('uuid')
5 | id = undefined;
我猜是因为我的 babel 配置错误或不完整。如果有帮助,我大致按照我在这里找到的内容进行操作:https://github.com/typeorm/babel-example。
产生错误的命令是 $ ./node_modules/.bin/babel-node ./node_modules/.bin/typeorm schema:drop
(已编辑)
您使用的示例存储库用于 JavaScript 代码,而不是 TypeScript。如果您想将它与 TypeScript 代码一起使用,您可以尝试在 .babelrc
中启用 transform-typescript
插件,但最好使用 here 中的 TypeScript 示例之一。或者,只需删除 abstract
。 (abstract
是 TypeScript 独有的功能。)