Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type-introspection with macros #9561

Open
johnpyp opened this issue Mar 2, 2024 · 0 comments
Open

Type-introspection with macros #9561

johnpyp opened this issue Mar 2, 2024 · 0 comments

Comments

@johnpyp
Copy link

johnpyp commented Mar 2, 2024

🙋 feature request

Support introspecting types, annotations, and more in macros. My main theoretical usecase is writing a zod-type library that doesn't require advanced conditional typescript, and can compile to the most performant version of serializers and deserializers. Very similar to Serde.

🤔 Expected Behavior

I don't know exactly the semantics of how this behavior might work, but here's an example of what I'd like to be able to do:

import { Serde, Field } from 'serde'
import {  objectDeserialize, jsonDeserialize } from 'serde' with { type: 'macro' }

@Serde
class MyData {
  @Field({ minLength: 10 })
  public password: string

  @Field({ validateEmail: true })
  public email: string;
}

const myResponse = Response(...)

// Deserialize from string
const jsonDecoded = jsonDeserialize<MyData>(await myResponse.text())

// Deserialize from untyped object
const objectDeserialize = objectDeserialize<MyData>(await myResponse.json())

😯 Current Behavior

Can't introspect type arguments to be able to code-gen against it

💁 Possible Solution

Not really sure how to implement it

🔦 Context

See the example above :)

💻 Examples

See the example above :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants