请问 typescript 中应该如何在 interface 使用计算属性?

enum LEVELS {
  debug = 0,
  warn,
  error,
  info,
}
export default interface ILogger {
  [LEVELS[LEVELS.debug]]: ([prop]: any) => void;
  [LEVELS[LEVELS.warn]]: Function;
  [LEVELS[LEVELS.error]]: Function;
  [LEVELS[LEVELS.info]]: Function;
}
class Logger implements ILogger {
    debug(){}
    warn(){}
    error(){}
    info(){}
}

写了一个enum 一个接口像上面这样,但是出现了错误

A computed property name in an interface must refer to an expression whose type is a literal type or a 'unique symbol' type.
阅读 2k
1 个回答
export type ILogger = Record<LEVELS, Function>
推荐问题
logo
Microsoft
子站问答
访问
宣传栏