Fork me on GitHub
#malli
<
2023-12-01
>
Rob Haisfield16:12:57

Would really love if there were a plug and play way to use Malli with a TypeScript library

lukasz17:12:06

I'm looking into this - I haven't made much progress, but all the pieces are there: • Malli can generate JSON Schemas: https://github.com/metosin/malli/blob/master/src/malli/json_schema.cljc • There's many ways of turning JSON Schemas into Typescript types I have a working system that uses Avro schemas that generates Typescript types, but it requires quite a lot of work to use these types in the frontend code. Based on my research and experience something like this: https://redux-toolkit.js.org/rtk-query/usage/code-generation#openapi seems to be way more maintainable .

escherize19:12:01

I haven’t used it, but there’s a library for generating typescript types from malli schemas: https://github.com/flowyourmoney/malli-ts

twashing21:12:19

Is there a fn or approach to do a Clojure-style merge on a malli.core/schema?

(def custom-registry
  {::thing [:map [:a :string]]})

(def Foo
  (m/schema
   [:schema {:registry custom-registry}
    ::thing]
   {:registry default-registry}))

(type (m/deref Foo))  ;; :malli.core/schema
(type Foo)            ;; :malli.core/schema

;; Not working
(m/schema
 [:merge
  Foo
  [:map [:b :string]]])

=> clojure.lang.ExceptionInfo: :malli.core/invalid-schema {:schema :merge}
   {:type :malli.core/invalid-schema, :message :malli.core/invalid-schema, :data {:schema :merge}}

ikitommi12:12:26

try malli.util/merge. there is the :merge schema, but it’s not included in the default registry, so you have to register or reference it to use it.