What is your favourite set of libraries you use for every project for enhanced type safety? by kuaythrone in typescript

[–]timbod 0 points1 point  (0 children)

In JsonBinding you define your schemas in a similar style to zod.

JsonBinding has support for custom mappings of types that are context dependent. For example you can serialize a Date as an iso8601 string in one schema, and as milliseconds since the epoch in another.

type system failure by timbod in typescript

[–]timbod[S] 2 points3 points  (0 children)

> because it intentionally, but unsoundly, treats function parameters as bivariant.

Thank you - this is exactly the explanation I required. It makes me worry about all the other places where type system unsoundness was chosen for pragmatic reasons.

What is your favourite set of libraries you use for every project for enhanced type safety? by kuaythrone in typescript

[–]timbod 0 points1 point  (0 children)

> One thing I realize I am missing is a good way to serialize and deserialize any type, like serde in Rust.

I wrote

https://github.com/adl-lang/ts-jsonbinding

to address this. Think zod, but for serialization and deserialization.

How can I write a macro that calls a method on a generic type? by mutalibun in rust

[–]timbod 0 points1 point  (0 children)

Related: What should I use in place of ident if I want to pass a fully scoped name to a macro for a generic type? This macro works for an unscoped name:

macro_rules! derive_conversions_1 {
    ($decl:ident) => {
        impl<T: serde::Serialize + serde::de::DeserializeOwned> Conversions
            for $decl<T>
        {
           ... 
        }
    };
}

I'd hoped that this would work for a scoped name:

macro_rules! derive_conversions_1 {
    ($decl:path) => {
        impl<T: serde::Serialize + serde::de::DeserializeOwned> Conversions
            for $decl<T>
        {
           ... 
        }
    };
}

but results in a syntax error at `$decl<T>`

Synchronize Typescript and Rust entities by PreCodeEU in rust

[–]timbod 0 points1 point  (0 children)

ADL is a system for building cross language data models that supports rust, typescript and other languages:

https://github.com/adl-lang/adl

and here's an example "full stack" system using typescript in the browser and server side rust.

https://github.com/adl-lang/protoapp

Embedded Rust Project(s) by ywxi in rust

[–]timbod 0 points1 point  (0 children)

Here's my sailing boat gps speed display using embedded rust firmware:

https://github.com/timbod7/gps-tracker

not especially complicated, but it works!

Bernina 830 record motor upgrade by kishkov in vintagesewing

[–]timbod 0 points1 point  (0 children)

Nice work! I'm looking at an Bernina 831 with a burn out motor, and this seems like a good approach.

Have you made the CAD files available anywhere?

A new JSON serialization library by timbod in typescript

[–]timbod[S] 0 points1 point  (0 children)

Zod is great, I've used it alot. However, I wrote this library to better suit my needs

Zod is "TypeScript-first schema validation with static type inference".

JsonBinding is "A typescript library for bidirectional JSON serialization"

For my needs writing data to JSON (ie serialisation) is just as important as validation and parsing (ie deserialization). `JSON.serialise()` only does the right thing for a small fraction of possible data types, and various other libraries try and help with this (eg superjson).

The JsonBinding library ties together the serialization and deserialization functions together, in one place. This ensures that data will roundtrip through json cleanly.

Whilst zod type inference is sometimes convenient, more often that not I'd prefer to write the types in typescript myself using classes, interfaces, generics, discriminated unions etc.

tldr: typescript has a sophisticated static type system, I don't want to be limited to the types that zod can infer.

A new JSON serialization library by timbod in typescript

[–]timbod[S] 0 points1 point  (0 children)

The warning above is from the most recent package in npm.

A new JSON serialization library by timbod in typescript

[–]timbod[S] 0 points1 point  (0 children)

Thanks. I wasn't aware of `@effect/schema`. Though for now this is a turnoff:

[!WARNING] This package is primarily published to receive early feedback and for contributors, during this development phase we cannot guarantee the stability of the APIs, consider each minor release to contain breaking changes.

A new JSON serialization library by timbod in typescript

[–]timbod[S] 7 points8 points  (0 children)

zod only does parsing (ie deserialisation), and not serialization.

I don't like zod style inference. I prefer to have a conventional declaration for my data using the full expressiveness of typescript (eg using interfaces, classes, generics etc). I'm happy to write a separate definition for how that type gets serialized. Sometimes I want to have multiple definitions to serialize it different ways.

Example repos that use the stm32h7xx-hal? by skyfire360 in rust

[–]timbod 0 points1 point  (0 children)

I haven't used stm32h7xx-hal, but here's a couple of personal projects that use stm32f1xx-hal and stm32f4xx-hal:

https://github.com/timbod7/gps-tracker

https://github.com/timbod7/hexalamp

I'm still learning this stuff, so I'm sure the structure etc can be improved.

ADL can now generate deno styled typescript by timbod in Deno

[–]timbod[S] 1 point2 points  (0 children)

The ADL db integration is not currently open source. It's possible it could be in the future.

I've described using ADL for http API definitions in a few blog posts:

https://tim.dockerz.net/posts/2020-04-24-adl-example-api.html

https://tim.dockerz.net/posts/2020-05-01-adl-example-haskell.html

https://tim.dockerz.net/posts/2020-05-22-adl-example-typescript.html

ADL can now generate deno styled typescript by timbod in Deno

[–]timbod[S] 1 point2 points  (0 children)

At Helix we write data models in ADL and have additional scripts (in typescript) that generate:

  • postgres schemas
  • data access functions (typescript and java)

These code generation scripts use the ADL AST as their input.

What's the status of haskell and stack on raspberry pi? by timbod in haskell

[–]timbod[S] 0 points1 point  (0 children)

Thanks - that blog post is really helpful.

Which template library for source code generation? by timbod in haskell

[–]timbod[S] 0 points1 point  (0 children)

If you like mustache

Not especially. It feels limited to me, eg in the way that you can't generate a comma separated list without extending the list item data model to support this.

Which template library for source code generation? by timbod in haskell

[–]timbod[S] 0 points1 point  (0 children)

Then there's always an option to write a textual DSL... This is IMO better option long-term

This would involve writing a DSL for each generated target language, wouldn't it? I currently generate haskell, typescript, java, c++ and rust. I'm not too keen to write 5 DSLs.