ianstormtaylor / superstruct

A simple and composable way to validate data in JavaScript (and TypeScript).
https://docs.superstructjs.org
MIT License
6.95k stars 224 forks source link

Does "create" supports "passthrough" #1233

Closed Bonjour123 closed 1 month ago

Bonjour123 commented 3 months ago

When using Superstruct for data coercion, can I allow other non-defined fields ? Same as zod's passthrough method.

yeoffrey commented 2 months ago

I would use type here.

import { assert, string, type } from 'superstruct'

const myStruct = type({ name: string() })

const data = {
  name: 'yeoffrey',
  age: 23,
}

assert(data, myStruct) // Passes
arturmuller commented 1 month ago

I'm closing this as @yeoffrey seems to have answered the question.

@Bonjour123 if you have any more detail about this or further questions, please head over to our newly opened GitHub Discussions page — we'll be happy to help you out there! :)