From 9df7b1362ac3831a4d6eb627892c5073bc6e9d11 Mon Sep 17 00:00:00 2001 From: "Vitaliy V. Makeev" Date: Fri, 29 Jul 2022 08:57:50 +0500 Subject: [PATCH] test: add TS checker stuck test --- .../{expensive.test.ts => expensive1.test.ts} | 0 test/model/expensive2.test.ts | 109 ++++++++++++++++++ 2 files changed, 109 insertions(+) rename test/model/{expensive.test.ts => expensive1.test.ts} (100%) create mode 100644 test/model/expensive2.test.ts diff --git a/test/model/expensive.test.ts b/test/model/expensive1.test.ts similarity index 100% rename from test/model/expensive.test.ts rename to test/model/expensive1.test.ts diff --git a/test/model/expensive2.test.ts b/test/model/expensive2.test.ts new file mode 100644 index 0000000..8d39e8e --- /dev/null +++ b/test/model/expensive2.test.ts @@ -0,0 +1,109 @@ +// ВНИМАНИЕ! +// Это очень тяжелый тест. Он "убивает" производительность чекера TS. +// После каждого изменения чекер задумывается на несколько секунд. + +// FIXME Можно что-то сделать с этим? И вооще как понять в чем причина тормозов? + +import type { + Agent, + Assortment, + Counterparty, + CustomerOrder, + CustomerOrderPosition, + Expand, + MetaType, + Organization, + Product, + State +} from '../../src' +import { flatMap, map } from '../../src/array' +import fp from 'lodash/fp' +import _ from 'lodash' + +const order = {} as CustomerOrder + +order.agent.meta.type +order.agent.meta.href + +const expandedOrder = {} as Expand< + CustomerOrder, + 'agent,state,positions.assortment.supplier' +> + +//#region Такой вариант расширения не работает с .map (тип обрезается) +// const expandedOrder = {} as CustomerOrder & { +// agent: Counterparty | Organization +// } & { state: State | undefined } & { +// positions: { +// rows: CustomerOrderPosition[] +// } +// } & { +// positions: { +// rows: Array<{ +// assortment: Product +// }> +// } +// } & { +// positions: { +// rows: Array<{ +// assortment: { supplier: Counterparty | Organization } +// }> +// } +// } +//#endregion + +expandedOrder.agent.name +expandedOrder.state?.stateType +expandedOrder.positions.rows[0].quantity +expandedOrder.positions.rows[0].assortment.name +expandedOrder.positions.rows[0].assortment.supplier?.companyType + +//#region Нативный map - медленно!!! +// const productNames = expandedOrder.positions.rows.map(row => { +// return row.assortment.name +// }) +//#endregion + +//#region Обернутый map - быстро +const productNames3 = map(expandedOrder.positions.rows, row => { + return row.assortment.name +}) +//#endregion + +//#region Обернутый flatMap - быстро +const productNames4 = flatMap(expandedOrder.positions.rows, row => { + return [row.assortment] +}) + +productNames4[0].alcoholic +//#endregion + +//#region lodash.fp.map - быстро +const productNames5 = fp.map((row: { assortment: { name: string } }) => { + return row.assortment.name +})(expandedOrder.positions.rows) +//#endregion + +//#region lodash.map +const productNames6 = _.map(expandedOrder.positions.rows, row => { + return row.assortment.name +}) +//#endregion + +//#region lodash.map - медленно !!! +// const productNames6 = _(expandedOrder.positions.rows) +// .map(row => { +// return row.assortment.name +// }) +// .flatMap(it => it.trim()) +//#endregion + +//#region sample 3 (map через цикл - быстро) +const productNames = [] + +for (const row of expandedOrder.positions.rows) { + productNames.push(row.assortment.name) +} + +productNames +//#endregion