Skip to content

Commit

Permalink
fix(Expand): revert some changes
Browse files Browse the repository at this point in the history
- add test
  • Loading branch information
wmakeev committed Aug 3, 2021
1 parent 5094d4a commit cc3770d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/model/utils/Expand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ export type ExpandPath<T, K extends string> =
* Разворачивает поля типа по строке expand в формате API МойСклад
*/
export type Expand<T, U extends string | undefined> =
string extends U
// Исходный тип если expand не задан
U extends undefined
? T

: string extends U
? never

// 'foo.bar,baz'
Expand All @@ -139,5 +143,5 @@ export type Expand<T, U extends string | undefined> =
: U extends string
? ExpandPath<T, U>

// Исходный тип если expand не задан
: T

: never
16 changes: 12 additions & 4 deletions test/model/utils/Expand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const t08_11_1 = {} as ExpandedField<
>
const t08_11_2: AssortmentMetaType = t08_11_1.meta.type

// TODO Что это за тест? Удалить?
// const t80_20_1 = {} as ExpandField<CustomerOrder, 'positions'>
// const t80_20_2: EntityRef<
// 'product' | 'service' | 'bundle' | 'consignment' | 'variant'
Expand All @@ -56,8 +57,15 @@ const t08_11_2: AssortmentMetaType = t08_11_1.meta.type
const t71: 'foo' = {} as Expand<'foo', undefined>
t71

const t70: CustomerOrder = {} as Expand<CustomerOrder, undefined>
t70
const t70 = {} as Expand<CustomerOrder, undefined>
t70.shippedSum

const t72 = {} as Expand<Collection<Account>, string | undefined>
t72.rows[0].accountNumber

// @ts-expect-error only string or undefined
const t73 = {} as Expand<Collection<Account>, 42>
t73

//#endregion

Expand Down Expand Up @@ -228,14 +236,14 @@ const t55_3 = {} as ExpandField<
'value'
>
const t55_4: Entity<'customentity'> = t55_3.value
t55_4
t55_4.id

const t55_5 = {} as ExpandField<
AttributeBase<AttributeType.Counterparty>,
'value'
>
const t55_6: Counterparty = t55_5.value
t55_6
t55_6.actualAddress

const t55_7 = {} as Expand<CustomerOrder, 'attributes.value'>

Expand Down

0 comments on commit cc3770d

Please sign in to comment.