Skip to content

Type introspection at runtime #686

Answered by ssalbdivad
strogonoff asked this question in Q&A
Discussion options

You must be logged in to vote

You're looking for the .node prop!

Each type is internally represented using objects like this:

const myType = type("number%2 | string<10")
// { number: {divisor: 2}, string:  { limit: 10, comparator: "<" } }
console.log(myType.node)

Internally, these nodes represent a full type system that can determine assignability between any two types, with utilities for doing things like extracting props.

You can even create types directly from these node structures using a tuple expression with full static-inference!

        const t = type([
            "node",
            {
                object: {
                    class: Array,
                    props: {
                        "[index]": { o…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@strogonoff
Comment options

@ssalbdivad
Comment options

Answer selected by ssalbdivad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #685 on March 15, 2023 17:43.