arktypeio / arktype

TypeScript's 1:1 validator, optimized from editor to runtime
https://arktype.io/
MIT License
3.94k stars 60 forks source link

Type `.assert` functions no longer usable as passed variables without explicit binding #1145

Closed fnimick closed 1 month ago

fnimick commented 1 month ago

Report a bug

.assert functions from types are no longer usable as passed-around functions. They must be explicitly bound.

This breaks trpc's arktype integration, where they describe using .input(type(...).assert) to use arktype for input type validation.

This

🔎 Search Terms

trpc, Cannot read properties of undefined (reading 'traverse'),

🧩 Context

System: OS: macOS 15.0 CPU: (10) arm64 Apple M1 Pro Memory: 123.61 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.13.1 - ~/.asdf/installs/nodejs/20.13.1/bin/node Yarn: 1.22.19 - ~/.yarn/bin/yarn npm: 10.5.2 - ~/.asdf/plugins/nodejs/shims/npm pnpm: 9.7.0 - ~/.asdf/shims/pnpm npmPackages: arktype: ^2.0.0-rc.12 => 2.0.0-rc.12 typescript: ^5.5.4 => 5.5.4

🧑‍💻 Repro

let test = type("string")
let testFn = (inputFn) => inputFn({})
testFn(test.assert)
fnimick commented 1 month ago

My very silly workaround for now:

export function getAssert<T extends type.Any>(type: T) {
  return type.assert.bind(type);
}
Dimava commented 1 month ago

@fnimick trpc now has builtin arktype support, use that https://github.com/trpc/trpc/pull/5958

ssalbdivad commented 1 month ago

Fixed in 2.0.0-rc.13