Package Exports
- @empathyco/x-types
- @empathyco/x-types/dist/cjs/index.js
- @empathyco/x-types/dist/esm/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@empathyco/x-types) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
x-types
TypeScript model types, guards, and jest schemas to use across the X project.
How to install
npm install @empathyco/x-types --saveHow to use
The package export several model types that can be used to safely create objects that match the expectations of X packages.
import { RelatedTag } from '@empathyco/x-types'
const relatedTag: RelatedTag = {
query: 'lego',
tag: 'city',
selected: false,
previous: 'lego',
}Additionally it also exposes some type guards to check between different types.
import { Filter, isHierarchicalFilter } from '@empathyco/x-types'
const filter: Filter = {
modelName: 'HierarchicalFilter',
id: 'color:red',
facetId: 'color',
label: 'red',
selected: false,
children: [],
}
// You can't access filter.children before the `if` because you have a `Filter`, not a `HierarchicalFilter`.
if (isHierarchicalFilter(filter)) {
// But after using the `isHierarchicalFilter` guard, you can acces it.
console.log('Children:', filter.children)
}Finally, there are some jest schemas helpers that you could use to validate your objects.
import { Filter, isHierarchicalFilter } from '@empathyco/x-types'
import { HierarchicalFilterSchema } from '@empathyco/x-types/schemas'
it('is a hierarchical filter', () => {
const filter: Filter = {
modelName: 'HierarchicalFilter',
id: 'color:red',
facetId: 'color',
label: 'red',
selected: false,
children: [],
}
expect(filter).toEqual(HierarchicalFilterSchema)
})How to update the version
You can check if a new version has been published running npm outdated:
npm outdated @empathyco/x-types
And update it using npm update:
npm update --save @empathyco/x-types