josdejong / josdejong/ducktype

Are recursive types supported?

Open
#40 5 comments 0 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
JavaScript
Stars
92
Forks
6
PR merge metrics
No merged PRs in 30d

Description

Is it possible to define a type e.g. "segment" that is either a string, a number, or an array of segments (recursive definition)? If not, please consider it a feature request.

Something like:

```js
const segment = ducktype.indirect();
segment.that = ducktype(String, Number, [segment]);
```

or even:

```js
const segment = ducktype.recursive(self => ducktype(String, Number, [self]));
```
Basically I need to validate that all "leaves" of a non-flat array are of a particular union type. I cannot flatten the array before validating because it is nested in a bigger data structure that I want to validate as a whole (as opposed to picking these arrays out of it for flattening and validation), and the nesting structure within the array is meaningful.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.