Typescript 使映射的键成为类型,而不必复制类型联合声明中的所有键?

Typescript 使映射的键成为类型,而不必复制类型联合声明中的所有键?,typescript,Typescript,在下面的代码中,我想使用Keys类型键入参数a。我正在复制“第一”、“第二”、“第三”键来实现这一点。我能在不重复钥匙的情况下完成同样的事情吗 type Keys = "first" | "second" | "third"; const someMap = new Map<Keys, string>([ ["first", "yes, master"], ["second", "what do you want?"], ["third", "poke, poke, p

在下面的代码中,我想使用Keys类型键入参数
a
。我正在复制“第一”、“第二”、“第三”键来实现这一点。我能在不重复钥匙的情况下完成同样的事情吗

type Keys = "first" | "second" | "third";

const someMap = new Map<Keys, string>([
  ["first", "yes, master"],
  ["second", "what do you want?"],
  ["third", "poke, poke, poke - is that all you do?"],
]);

function func(a: Keys) {
  console.log(someMap.get(a));
}
type Keys=“first”|“second”|“third”;
const someMap=新映射([
[“第一”,“是的,主人”],
[“第二”,“你想要什么?”],
[“第三”,“戳,戳,戳-你就这么做了吗?”,
]);
函数func(a:键){
log(someMap.get(a));
}