Skip to content

.onUndeclaredKey('delete') does not work if added before .pipe(), on a type.or() schemaΒ #1514

@NamesMT

Description

@NamesMT

Report a bug

πŸ”Ž Search Terms

onUndeclaredKey

🧩 Context

  • ArkType version: 2.1.22
  • TypeScript version (5.1+): 5.9.2
  • Other context you think may be relevant (JS flavor, OS, etc.):

πŸ§‘β€πŸ’» Repro

Playground Link: https://arktype.io/playground?code=import%2520%257B%2520type%2520%257D%2520from%2520%2522arktype%2522%250A%250Aconst%2520Thing%2520%253D%2520type%28%257B%250A%2509name%253A%2520%2522string%2522%252C%250A%2509sample%253A%2520type%250A%2509%2509.or%28%250A%2509%2509%2509type%28%257B%2520title%253A%2520%27%2522OK%2522%27%252C%2520%2522description%253F%2522%253A%2520%2522string%2522%2520%257D%29%252C%250A%2509%2509%2509type%28%257B%2520title%253A%2520%27%2522KO%2522%27%252C%2520%2522description%253F%2522%253A%2520%2522string%2522%2520%257D%29%250A%2509%2509%29%250A%2509%2509.onUndeclaredKey%28%2522delete%2522%29%250A%2509%2509.pipe%28%28v%29%2520%253D%253E%2520%257B%250A%2509%2509%2509if%2520%28v.description%29%2520v.description%2520%253D%2520%2522Hello%2522%2520%252B%2520v.description%250A%2509%2509%2509return%2520v%250A%2509%2509%257D%29%250A%257D%29%250A%250Aconst%2520out%2520%253D%2520Thing%28%257B%250A%2509name%253A%2520%2522TypeScript%2522%252C%250A%2509sample%253A%2520%257B%250A%2509%2509%2509title%253A%2520%2522OK%2522%252C%250A%2509%2509%2509description%253A%2520%2522World%2522%252C%250A%2509%2509%2509_meta%253A%2520%2522SHOULD%2520BE%2520REMOVED%2522%250A%2509%2509%257D%250A%257D%29%250A

import { type } from "arktype"

const Thing = type({
	name: "string",
	sample: type
		.or(
			type({ title: '"OK"', "description?": "string" }),
			type({ title: '"KO"', "description?": "string" })
		)
		.onUndeclaredKey("delete")
		.pipe((v) => {
			if (v.description) v.description = "Hello" + v.description
			return v
		})
})

const out = Thing({
	name: "TypeScript",
	sample: {
			title: "OK",
			description: "World",
			_meta: "SHOULD BE REMOVED"
		}
})

Additional comments

  • If .onUndeclaredKey is used after .pipe, it works fine.
  • If the level 1 is a simple object schema, it works fine, only bugged when used on a type.or() schema.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

To do

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions