search

Home  >  Q&A  >  body text

javascript - How to make Types.TYPE1 of import * as Types as the key value of json attribute?

Normal situation: String constants such as const TYPE1 can be used as json attribute keys, for example:

const TYPE1 = "TYPE1"
const mapper = 
{
    TYPE1 : param=>param
}

However, in order to facilitate the reference of a large number of type constants, I put all the type constants in a separate file and referenced them through alias. The above code becomes like this:

import * as Types from './types.js'
const mapper = 
{
    Types.TYPE1 : param=>param
}

Of course, this usage is wrong.

Question:
How to use Types.TYPE1 as the key of json when you want to use import * as Types from './types.js' to reference constants?

我想大声告诉你我想大声告诉你2750 days ago473

reply all(1)I'll reply

  • 滿天的星座

    滿天的星座2017-05-19 10:16:22

    const mapper = 
    {
        [Types.TYPE1] : param=>param
    }

    reply
    0
  • Cancelreply