Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create custom datatype in typescript?

I have a object like below

export const appErrorTemplate = {
    NO_APP : {
        template : 'Unable to initialize #{0}()!',
        code : 'no-app'
    },
    NO_REQ_FOUND : {
        template : '#{0}() requires \'#{1}\' to process!',
        code : 'no-required-found'
    },
    MISMATH : {
        template : '#{0}() required #{1} but \'#{2}\' found!',
        code : 'mismatch'
    },
    NOT_SATISFY : {
        template : 'Given parameter on #{0}() does not satisfied #{1} constrains',
        code : 'not-satisfy'
    },
    UNKNOWN : {
        template : 'Something went wrong!',
        code : 'unknown'
    }
};

How to define datatype like object which has array of object on that each object will be string,string

like image 913
ned5 Avatar asked Sep 28 '18 02:09

ned5


1 Answers

It looks like you have not an array, but an object with a variable set of properties all of the same type. That can be described with a string index signature.

type AppErrorTemplateType = {
    [name: string]: {
        template: string,
        code: string
    }
};
like image 144
Matt McCutchen Avatar answered Sep 26 '22 19:09

Matt McCutchen