Skip to content

Instantly share code, notes, and snippets.

@sunrabbit123
Last active November 14, 2022 05:59
Show Gist options
  • Save sunrabbit123/21e8c93604d8c260f9dae936cb9adf78 to your computer and use it in GitHub Desktop.
Save sunrabbit123/21e8c93604d8c260f9dae936cb9adf78 to your computer and use it in GitHub Desktop.
const PROGRAMING_LANGUAGE = {
  python : "Python",
  javascript : "JavaScript"
} as const;
type PROGRAMING_LANGUAGE = typeof PROGRAMING_LANGUAGE[keyof typeof PROGRAMING_LANGUAGE];

const arg1 : PROGRAMING_LANGUAGE = PROGRAMING_LANGUAGE.python

compiled

var PROGRAMING_LANGUAGE = {
    python: "Python",
    javascript: "JavaScript"
};
var arg1 = PROGRAMING_LANGUAGE.python;

but using enum

enum PROGRAMING_LANGUAGE_ENUM {
  python = "Python",
  javascript = "JavaScript",
}

const arg2: PROGRAMING_LANGUAGE_ENUM = PROGRAMING_LANGUAGE_ENUM.javascript;

compiled

var PROGRAMING_LANGUAGE_ENUM;

(function (PROGRAMING_LANGUAGE_ENUM) {
    PROGRAMING_LANGUAGE_ENUM["python"] = "Python";
    PROGRAMING_LANGUAGE_ENUM["javascript"] = "JavaScript";
})(PROGRAMING_LANGUAGE_ENUM || (PROGRAMING_LANGUAGE_ENUM = {}));

var arg2 = PROGRAMING_LANGUAGE_ENUM.javascript;

enum is not working tree-shaking just code is The cord is getting longer.

tree-shaking is to delete code when code not use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment