typescript-is icon indicating copy to clipboard operation
typescript-is copied to clipboard

runtime representation of types as objects

Open DetachHead opened this issue 3 years ago • 2 comments

it would be cool if you could so something like this:

interface Foo {
    foo: string
    bar?: number
    baz?: Bar | boolean
}

interface Bar {
    foo: boolean
    bar: any
}

const foo = getTypeDetails<Foo>()

and it gets transformed to something like:

const foo = {
    foo: ['string'],
    bar: ['number', 'undefined'],
    baz: [
        { foo: 'boolean', bar: 'any' },
        'boolean',
        'undefined'
    ]
}

DetachHead avatar Feb 10 '21 10:02 DetachHead

Indeed it's a nice idea, but I consider it out of scope for this project.

Something like this exists here: https://github.com/YousefED/typescript-json-schema or https://github.com/vega/ts-json-schema-generator

woutervh- avatar Feb 11 '21 19:02 woutervh-

Thanks. I also found this project which seems more like what I have in mind https://github.com/awerlogus/io-ts-transformer, though it seems to be broken

Not sure how I missed it as it's mentioned in the readme here.

DetachHead avatar Feb 11 '21 20:02 DetachHead