gloriaJun / til

Lessoned Learned
3 stars 0 forks source link

Typescript set object with object key #96

Open gloriaJun opened 3 years ago

gloriaJun commented 3 years ago
interface IBranchInfo {
  master: string;
  develop: string;
  release: string;
  hotfix: string;
}

export const setBranchPrefix = (info: IBranchInfo) => {
  const keys = Object.keys(info) as Array<keyof IBranchInfo>;

  keys.map((k: keyof IBranchInfo) => {
    if (isNotEmpty(info[k])) {
      branchInfo[k] = info[k];
    }
  });
};
gloriaJun commented 3 years ago
const levels = {
  trace: 1,
  debug: 2,
  info: 3,
  warn: 4,
  error: 5,
  silent: 10,
} as const;

type levelKeys = keyof typeof levels;
type levelValues = typeof levels[levelKeys];

const currentLogLevel = levels[<levelKeys>process.env.LOG_LEVEL] || levels.info;