const commands = ['foo', 'bar', 'hoge'] as const;
type Command = typeof commands[number];
const countryCode = {
jp: 'japan',
us: 'us',
};
type Code = keyof typeof countryCode;
const c: Code = 'jp';
// error
const c: Code = 'ch';
関数宣言は hoisting できるが、関数式は hoisting できない
関数宣言 → プログラムの実行開始時から既に存在している
関数式 → ただの変数宣言なのでプログラムは上から下に実行される
foo();
function foo() {
return 'foo';
}
// error
bar();
const bar = () => {
return 'bar';
};