-
-
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.
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
4ce8664
commit 9e988ea
Showing
5 changed files
with
117 additions
and
7 deletions.
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 |
---|---|---|
|
@@ -129,6 +129,9 @@ | |
"resolutions": { | ||
"@types/unist": "3.0.2" | ||
}, | ||
"engines": { | ||
"node": ">=18.18.2" | ||
}, | ||
"packageManager": "[email protected]", | ||
"sideEffects": false | ||
} |
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,22 @@ | ||
/** | ||
* @file Type Tests - Children | ||
* @module unist-util-types/tests/unit-d/Children | ||
*/ | ||
|
||
import type * as docast from '@flex-development/docast' | ||
import type * as mdast from 'mdast' | ||
import type TestSubject from '../children' | ||
|
||
describe('unit-d:Children', () => { | ||
it('should equal T["children"] if T extends Parent', () => { | ||
// Arrange | ||
type T = docast.Comment | ||
|
||
// Expect | ||
expectTypeOf<TestSubject<T>>().toEqualTypeOf<T['children']>() | ||
}) | ||
|
||
it('should equal never if T does not extend Parent', () => { | ||
expectTypeOf<TestSubject<mdast.InlineCode>>().toEqualTypeOf<never>() | ||
}) | ||
}) |
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,28 @@ | ||
/** | ||
* @file Children | ||
* @module unist-util-types/Children | ||
*/ | ||
|
||
import type { Node, Parent } from 'unist' | ||
|
||
/** | ||
* Extract [*children*][1] from [*tree*][2] `T`. | ||
* | ||
* [1]: https://github.com/syntax-tree/unist#child | ||
* [2]: https://github.com/syntax-tree/unist#tree | ||
* | ||
* @see {@linkcode Node} | ||
* @see {@linkcode Parent} | ||
* | ||
* @example | ||
* type X = Children<Parent> // Node[] | ||
* @example | ||
* type X = Children<Node> // never | ||
* @example | ||
* type X = Children<Literal> // never | ||
* | ||
* @template {Node} T - Tree to try extracting children from | ||
*/ | ||
type Children<T extends Node> = T extends Parent ? T['children'] : never | ||
|
||
export type { Children as default } |
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