From dd099ec8d9a452c0612a26b47f1f257efb3cf0e6 Mon Sep 17 00:00:00 2001 From: Vitaliy Makeev Date: Tue, 20 Jul 2021 17:40:53 +0500 Subject: [PATCH] feat(Expand): pass through if expand string is undefined --- package.json | 2 +- src/model/utils/Expand.ts | 10 +++++++--- test/model/utils/Expand.test.ts | 10 ++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 4c7086e..3b7dec8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "moysklad-api-model", - "version": "0.2.10", + "version": "0.2.11", "description": "Объектная модель API МойСклад для TypeScript проектов", "main": "build/src/index.js", "types": "build/src/index.d.ts", diff --git a/src/model/utils/Expand.ts b/src/model/utils/Expand.ts index 5cc0b3f..2c38cb5 100644 --- a/src/model/utils/Expand.ts +++ b/src/model/utils/Expand.ts @@ -74,8 +74,12 @@ export type ExpandPath = /** * Разворачивает поля типа по строке expand в формате API МойСклад */ -export type Expand = - string extends U +export type Expand = + // Исходный тип если expand не задан + U extends undefined + ? T + + : string extends U ? never // 'foo.bar,baz' @@ -83,7 +87,7 @@ export type Expand = ? ExpandPath & Expand // 'foo.bar' - : ExpandPath + : U extends string ? ExpandPath : never // TODO 'positions.assortment,agent.attributes.value' // TODO 'attributes.value,agent.attributes.value' diff --git a/test/model/utils/Expand.test.ts b/test/model/utils/Expand.test.ts index 2a9a648..67e73e4 100644 --- a/test/model/utils/Expand.test.ts +++ b/test/model/utils/Expand.test.ts @@ -9,6 +9,16 @@ import { Meta } from '../../../src' +//#region Пустой Expand + +const t71: 'foo' = {} as Expand<'foo', undefined> +t71 + +const t70: CustomerOrder = {} as Expand +t70 + +//#endregion + //#region Expand не должен затрагивать прочие поля const t00 = {} as Expand