简体   繁体   中英

Interface or type for symbol type of JavaScript in typescript?

I have some values of symbol type in javascript and I need to convert it into typescript.

// Object values in Javascript
const size = {
   Large: Symbol('large'),
   Medium: Symbol('medium')
}

What is the best way to convert it into typescript?

Will this work for you?

interface Size {

    LargeSize: symbol,
    MediumSize: symbol

}

const size:Size = {
   LargeSize: Symbol('large'),
   MediumSize: Symbol('medium')
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM