Giter VIP home page Giter VIP logo

Comments (5)

mycaule avatar mycaule commented on May 14, 2024 6

Found the answer in the unit tests, here is the way to do it:

https://github.com/ianstormtaylor/superstruct/blob/master/test/fixtures/object-lists/property-optional.js#L6

struct.optional(User),

or another way

const User = struct.optional({
  id: 'number',
  name: 'string',
})

Maybe you will have to update the docs.

from superstruct.

mycaule avatar mycaule commented on May 14, 2024 2

The | syntax should be documented too. It is already implemented.

Example :

meta: 'object | null'

from superstruct.

ianstormtaylor avatar ianstormtaylor commented on May 14, 2024 2

Documented now!

from superstruct.

Silic0nS0ldier avatar Silic0nS0ldier commented on May 14, 2024 1

struct.union([ 'object', 'null' ] achieves the same thing, for those following this. Comes in handy when validating more complex objects.

from superstruct.

mycaule avatar mycaule commented on May 14, 2024

The set of possible operations on structs (intersection, union, optional etc..) is already well documented here, except the one char short syntax. Got to be familiar with functional programming to connect the dots.
https://github.com/ianstormtaylor/superstruct/blob/master/docs/reference.md#structs

from superstruct.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.