B
B
BonBon Slick2020-06-24 07:29:28
JavaScript
BonBon Slick, 2020-06-24 07:29:28

Auto generated deep types?

headTabs: {
        title: string,
        isActive: boolean,
        icon: string,
        child?: {
            title: string,
            isActive: boolean,
            icon: string,
            child?: {
                title: string,
                isActive: boolean,
                icon: string
            }[],
        }[],
    }[]                       = [

        {
            title:    'Description',
            isActive: true,
            icon:     'fas  fa-file-alt',
            child:    [
                {
                    title:    'Videos',
                    isActive: true,
                    icon:     'fas  fa-file-alt',
                    child:    [
                        {
                            title:    'Series',
                            isActive: true,
...

Categories and their subcategories.
When a subcategory is selected, all tab parents are updated isActive

Is it possible to automatically generate a deep data type? Structure type?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Robur, 2020-06-24
@BonBonSlick

Generate from what? what is a "deep type"? for your example - write a recursive type with your hands from several lines and it will be enough, why generate something here?

type Category = {
        title: string
        isActive: boolean
        icon: string
        child?: Category
}

In general, no one bothers you to write a generator. But in fact - they are needed very rarely, mainly if it is some kind of external data, such as gql, or you have code generated in js, such as grpc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question