-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ Demand + RetailDemand + tools/isType
- Loading branch information
Showing
10 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './model' | ||
export * from './tools' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import type { DocumentWithPositions, HasVat, MetaType } from '.' | ||
|
||
export type Demand = DocumentWithPositions<MetaType.Demand> & HasVat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { DocumentWithPositions, MetaType } from '.' | ||
|
||
export interface RetailDemand | ||
extends DocumentWithPositions<MetaType.RetailDemand> { | ||
cashSum: number | ||
noCashSum: number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { EntityByMetaType, MetaType } from './model' | ||
|
||
export function isType<T extends MetaType>( | ||
metaType: T, | ||
entity: unknown | ||
): entity is EntityByMetaType[T] { | ||
return (entity as any)?.meta?.type === metaType | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { CustomerOrder, Demand, MetaType, RetailDemand } from '../../build/src' | ||
import { isType } from '../../src/tools' | ||
import { getTypedVar } from '../tools' | ||
|
||
const doc = getTypedVar<CustomerOrder | Demand | RetailDemand>() | ||
|
||
if (isType(MetaType.RetailDemand, doc)) { | ||
const type: MetaType.RetailDemand = doc.meta.type | ||
|
||
doc.cashSum | ||
} else { | ||
const type: MetaType.CustomerOrder | MetaType.Demand = doc.meta.type | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function getTypedVar<T>(): T { | ||
return null as any | ||
} |