Skip to content
Discussion options

You must be logged in to vote

If you reference the same morph directly, it's safe:

const myType = type({
	"props?": "string",
	"objectArray?": type(myData, "=>", toArray).or([
		type(myData.array()),
		"=>",
		toArray
	])
})

Referencing a morph directly (as opposed to wrapping in another anonymous arrow function) allows introspection to determine the types are equivalent.

There's actually a builtin Array.liftFrom keyword for this:

const myType = type({
	"props?": "string",
	"objectArray?": type.keywords.Array.liftFrom(myData)
})

Unfortunately, it runs into the same issue you mentioned.

I've created an issue to track identifying that case as safe from Array.liftFrom:

#1375

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Baben01
Comment options

Answer selected by Baben01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants