Skip to content

Commit

Permalink
feat(types): Child
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Mar 3, 2023
1 parent c60f6b1 commit f28274d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
export * from './enums'
export * from './interfaces'
export * from './nodes'
export * from './types'
15 changes: 4 additions & 11 deletions src/nodes/parent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
*/

import type { Type } from '#src/enums'
import type { Child } from '#src/types'
import type unist from 'unist'
import type Comment from './comment'
import type ImplicitDescription from './implicit-description'
import type Node from './node'
import type BlockTag from './tag-block'
import type InlineTag from './tag-inline'

/**
* **Parent** ([**UnistParent**][1]) represents an abstract interface in docast
Expand All @@ -18,25 +15,21 @@ import type InlineTag from './tag-inline'
* [1]: https://github.com/syntax-tree/unist#parent
* [2]: https://github.com/syntax-tree/unist#child
*
* @template Child - Child node type
* @template ChildNode - Child node type
* @template Data - Information from the ecosystem
*
* @extends {Node<Data>}
*/
interface Parent<
Child extends BlockTag | Comment | ImplicitDescription | InlineTag =
| BlockTag
| Comment
| ImplicitDescription
| InlineTag,
ChildNode extends Child = Child,
Data extends unist.Data = unist.Data
> extends Node<Data> {
/**
* List representing [*children*][1].
*
* [1]: https://github.com/syntax-tree/unist#child
*/
children: Child[]
children: ChildNode[]

/**
* Node variant.
Expand Down
30 changes: 30 additions & 0 deletions src/types/__tests__/child.spec-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @file Type Tests - Child
* @module docast/types/tests/unit-d/Child
*/

import type {
BlockTag,
Comment,
ImplicitDescription,
InlineTag
} from '#src/nodes'
import type TestSubject from '../child'

describe('unit-d:types/Child', () => {
it('should extract BlockTag', () => {
expectTypeOf<TestSubject>().extract<BlockTag>().not.toBeNever()
})

it('should extract Comment', () => {
expectTypeOf<TestSubject>().extract<Comment>().not.toBeNever()
})

it('should extract ImplicitDescription', () => {
expectTypeOf<TestSubject>().extract<ImplicitDescription>().not.toBeNever()
})

it('should extract InlineTag', () => {
expectTypeOf<TestSubject>().extract<InlineTag>().not.toBeNever()
})
})
20 changes: 20 additions & 0 deletions src/types/child.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @file Type Definitions - Child
* @module docast/types/Child
*/

import type {
BlockTag,
Comment,
ImplicitDescription,
InlineTag
} from '#src/nodes'

/**
* [*Child*][1] node types.
*
* [1]: https://github.com/syntax-tree/unist#child
*/
type Child = BlockTag | Comment | ImplicitDescription | InlineTag

export type { Child as default }
6 changes: 6 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @file Entry Point - Type Definitions
* @module docast/types
*/

export type { default as Child } from './child'

0 comments on commit f28274d

Please sign in to comment.