superstruct icon indicating copy to clipboard operation
superstruct copied to clipboard

Does "create" supports "passthrough"

Open Bonjour123 opened this issue 1 year ago • 1 comments

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

Bonjour123 avatar May 04 '24 11:05 Bonjour123

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

yeoffrey avatar Jun 22 '24 21:06 yeoffrey

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! :)

arturmuller avatar Jul 06 '24 09:07 arturmuller