TypeScript元数据反射在定义其他类之前引用这些类
我的代码库中有一些类型化实体,它们彼此有关系,形成循环依赖关系。由于装饰器元数据用于每个实体类,所以TypeScript在每个定义元数据的类之后插入代码。假设课程是TypeScript元数据反射在定义其他类之前引用这些类,typescript,webpack,next.js,typeorm,Typescript,Webpack,Next.js,Typeorm,我的代码库中有一些类型化实体,它们彼此有关系,形成循环依赖关系。由于装饰器元数据用于每个实体类,所以TypeScript在每个定义元数据的类之后插入代码。假设课程是业务和资格。在相关字段上,TypeScript将发出如下代码: var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c <
业务
和资格
。在相关字段上,TypeScript将发出如下代码:
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
const decorator = (target, thing) => {
};
class Business {
}
class Qualification {
}
__decorate([
decorator,
__metadata("design:type", Business)
], Qualification.prototype, "business", void 0);
在代码的后面,定义了业务
,但为时已晚:
let Business=(\u dec6=Object(typeorm\u WEBPACK\u IMPORTED\u MODULE\u 1\u[“Entity”])(),\u dec7=Object(typeorm\u WEBPACK\u IMPORTED\u MODULE\u 1\u列])(),\u dec8=Object(class\u validator\u WEBPACK\u IMPORTED\u MODULE\u 0\u[“IsString”](),\u dec9=Reflect.metadata(“design:type:type”,String),\u dec10=Object(typeorm\u WEBPACK\u导入列)]({
类型:“枚举”,
枚举:业务类型
}),dec11=Object(类验证器网页包导入的模块[列]),dec14=Reflect.metadata(“设计:类型”,对象),dec12=Reflect.metadata(“设计:类型”,对象),dec13=Object(类型化网页包导入的模块[列])(),dec14=Reflect.metadata(“设计:类型”,布尔),dec15=Object(类型化网页包导入的模块[列])(),_dec16=Reflect.metadata(“设计:类型”,日期类型==“未定义”?对象:日期),_dec17=Object(类型化\网页包\导入\模块\列”])({
可为空:真
}),dec18=Object(类验证器(类)dec18=Object(类验证器(类)dec18=Object(类)dec18=Object(类验证器(类)dec18=Object(类)dec18=Object(类)dec18=Object(类),dec20=Reflect.metadata(类),字符串),dec21=Object(typeorm(类)dec20=IMPORTED(类)dec1=Column)({
可为空:真
}),dec22=Object(类验证器,网页包,导入的模块,字符串),dec23=Object(类验证器,网页包,导入的模块,字符串),dec24=Reflect.metadata(“设计:类型”,字符串),dec25=Object(类型,网页包,导入的模块,字符串)({
可为空:真
}),dec26=Object(类验证器网页包导入的模块,字符串),dec27=Object(类验证器网页包导入的模块,字符串),dec30=Object(类验证器网页包导入的模块,字符串),dec28=Reflect.metadata(“设计:类型”,字符串),dec29=Object(类型,网页包导入的模块,列),dec30=Object(类验证器网页包导入的模块,字符串,字符串)(),_dec31=对象(类验证器_uuu网页包_u导入的模块_u0_uuu[“MaxLength”])(200),_dec32=反映元数据(“设计:类型”,字符串),_dec33=对象(类型格式_uu网页包_u导入的模块_u1_uu[“OneToMany”)(类型=>db_u所有实体_u网页包_u导入的模块_u*3_uuuuu[/“i”/“i”]、资格=>Qualification.business{
瀑布:对
}),dec34=Object(类验证器(类)dec34=Object(类)导入的(类)模块(类)模块(类),dec37=Object(类)验证器(类),数组(类),dec36=Object(类),dec36=Object(类),dec36=Object(类),dec36=Object(类),dec37=Object(类),dec37=Object(类)导入的(类)(类验证器网页包导入模块0验证[“验证生成”])(),dec39=对象(类验证器网页包导入模块0 IsIn)](\u其他类型类别网页包导入模块2验证类别*/“a”])。过滤器(c=>c.type=='business').map(c=>c.slug){
每个人:对
}),_dec40=Reflect.metadata(“设计:类型”,数组),_dec41=Object(typeorm_uuu网页包u导入的模块u 1 uuuuuuu[“列”])('simple-json'),_dec42=Object(class_validator_u网页包u导入的模块u 0 uuu[“IsArray”]),_dec43=Object(class_u验证程序u网页包u导入的模块0 uuu[“validated dec44=Object(class_validator_uuwebpack_uimported_MODULE_u0_uu[“ArrayMinSize”])(1),_dec45=对象(class_validator_uwebpack_uimported_MODULE_u0_u[“arraymaxize”](5),_dec46=Reflect.metadata(“设计:类型”,数组),_dec47=对象(typeorm_uwebpack_uimported_umodule 1_u1[“列”)({
类型:“枚举”,
枚举:定价计划
}),dec48=Object(类验证器,网页包,导入的模块,定价计划),dec49=Reflect.metadata(“设计:类型”,字符串),dec50=Object(类型,网页包,导入的模块,OneToMany)”)(类型=>\db,所有实体,导入的模块,BaseOffer*/“b”,offer=>offer.offer,offer=Reflect.dec51,数组),\u dec6(\u class3=(\u class4=(\u temp2=类业务扩展\u db\u所有\u实体\u网页包\u导入的\u模块\u 3\u[/*帐户*/“a”]{
构造函数(…参数){
超级(…args);
_initializerDefineProperty(此“名称”、_描述符3、此);
_initializerDefineProperty(此“类型”、_描述符4、此);
_initializerDefineProperty(此为“已批准”),_描述符5,此为);
_initializerDefineProperty(这是“自”,这是描述符6);
_initializerDefineProperty(此为“logoUrl”,描述符7,此为);
_initializerDefineProperty(这个“fein”,描述词8,这个);
_initializerDefineProperty(此为“电话号码”、_描述符9、此为);
_initializerDefineProperty(此为“bio”,描述符10,此为);
_初始值定义属性(本“资格”,描述词11,本);
_initializerDefineProperty(此为“业务类别”、_描述符12、此为);
_initializerDefineProperty(这是“地理位置”,描述词13,这是);
_initializerDefineProperty(这是“pricingPlan”,描述符14,这是);
_initializerDefineProperty(此“提供”、_描述符15、此);
}
}(描述符3=\uApplyDecoratedDescriptor(\uClass4.prototype,“name”,[\uDec7,\uDec8,\uDec9]{
对,,
可枚举:正确,
可写:对,
初始值设定项:null
}),_descriptor4=_applyDecoratedDescriptor(_class4.prototype,“type”,[u dec10,[u dec11,[u dec12]{
对,,
可枚举:正确,
可写:对,
初始值设定项:null
}),_descriptor5=_applydcoratedDescriptor(_class4.prototype,“isApproved”,[u dec13,[u dec14]{
对,,
可枚举:正确,
可写:对,
初始值设定项:null
}),_descriptor6=_applyDecoratedDescriptor(_class4.prototype,“自”,[u dec15,[u dec16]{
有限公司
diff --git a/webpack-config-dev.txt b/webpack-config-prod.txt
index f8a28c3..8e5fa4d 100644
--- a/webpack-config-dev.txt
+++ b/webpack-config-prod.txt
@@ -1,80 +1,82 @@
{
externals: [ [Function] ],
optimization: {
checkWasmTypes: false,
nodeEnv: false,
splitChunks: false,
runtimeChunk: undefined,
minimize: false,
minimizer: [ [TerserPlugin], [CssMinimizerPlugin] ]
},
context: 'C:\\Users\\Robbie\\Code\\fit-society',
node: { setImmediate: false },
entry: [AsyncFunction: entry],
output: {
path: 'C:\\Users\\Robbie\\Code\\fit-society\\.next\\server',
filename: [Function: filename],
libraryTarget: 'commonjs2',
hotUpdateChunkFilename: 'static/webpack/[id].[hash].hot-update.js',
hotUpdateMainFilename: 'static/webpack/[hash].hot-update.json',
- chunkFilename: '[name].js',
+ chunkFilename: '[name].[contenthash].js',
strictModuleExceptionHandling: true,
crossOriginLoading: undefined,
- futureEmitAssets: false,
+ futureEmitAssets: true,
webassemblyModuleFilename: 'static/wasm/[modulehash].wasm'
},
performance: false,
resolve: {
extensions: [
'.tsx', '.ts',
'.js', '.mjs',
'.jsx', '.json',
'.wasm'
],
modules: [ 'node_modules' ],
alias: {
'next/head': 'next/dist/next-server/lib/head.js',
'next/router': 'next/dist/client/router.js',
'next/config': 'next/dist/next-server/lib/runtime-config.js',
'next/dynamic': 'next/dist/next-server/lib/dynamic.js',
next: 'C:\\Users\\Robbie\\Code\\fit-society\\node_modules\\next',
'private-next-pages': 'C:\\Users\\Robbie\\Code\\fit-society\\src\\pages',
'private-dot-next': 'C:\\Users\\Robbie\\Code\\fit-society\\.next'
},
mainFields: [ 'main', 'module' ],
plugins: [ [Object] ]
},
resolveLoader: {
alias: {
'emit-file-loader': 'C:\\Users\\Robbie\\Code\\fit-society\\node_modules\\next\\dist\\build\\webpack\\loaders\\emit-file-loader',
'error-loader': 'C:\\Users\\Robbie\\Code\\fit-society\\node_modules\\next\\dist\\build\\webpack\\loaders\\error-loader',
'next-babel-loader': 'C:\\Users\\Robbie\\Code\\fit-society\\node_modules\\next\\dist\\build\\webpack\\loaders\\next-babel-loader',
'next-client-pages-loader': 'C:\\Users\\Robbie\\Code\\fit-society\\node_modules\\next\\dist\\build\\webpack\\loaders\\next-client-pages-loader',
'next-data-loader': 'C:\\Users\\Robbie\\Code\\fit-society\\node_modules\\next\\dist\\build\\webpack\\loaders\\next-data-loader',
'next-serverless-loader': 'C:\\Users\\Robbie\\Code\\fit-society\\node_modules\\next\\dist\\build\\webpack\\loaders\\next-serverless-loader',
'noop-loader': 'C:\\Users\\Robbie\\Code\\fit-society\\node_modules\\next\\dist\\build\\webpack\\loaders\\noop-loader',
'next-plugin-loader': 'C:\\Users\\Robbie\\Code\\fit-society\\node_modules\\next\\dist\\build\\webpack\\loaders\\next-plugin-loader'
},
modules: [ 'node_modules' ],
plugins: [ [Object] ]
},
module: {
rules: [ [Object], [Object], [Object] ],
strictExportPresence: true
},
plugins: [
ChunkNamesPlugin {},
DefinePlugin { definitions: [Object] },
- UnlinkRemovedPagesPlugin { prevAssets: {} },
- NoEmitOnErrorsPlugin {},
- NextJsRequireCacheHotReloader { prevAssets: null },
+ HashedModuleIdsPlugin { options: [Object] },
+ IgnorePlugin {
+ options: [Object],
+ checkIgnore: [Function: bound checkIgnore]
+ },
PagesManifestPlugin { serverless: false },
NextJsSsrImportPlugin { options: [Object] },
NextJsSsrImportPlugin {},
FilterWarningsPlugin { exclude: [Array] }
],
- mode: 'development',
+ mode: 'production',
name: 'server',
target: 'node',
- devtool: 'cheap-module-source-map'
+ devtool: false
}
{
"presets": [
[
"next/babel",
{
"class-properties": {
"loose": true
},
"styled-jsx": {
"plugins": [
"styled-jsx-plugin-postcss"
]
}
}
]
],
"plugins": [
"babel-plugin-transform-typescript-metadata",
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
]
]
}
export const ValidateableQualification = omit(Qualification, ['id', 'business', 'validity']);
export const RelationalEntities = [
Qualification,
Business,
// ...
]
@OneToMany(type => Qualification)
qualification!: Qualification;
// instead of (will not work)
@OneToMany(Qualification)
qualification!: Qualification;