Typescript通用对象属性常量名称在映射后丢失

Typescript通用对象属性常量名称在映射后丢失,typescript,Typescript,有没有一种不用“as”的方法 const names = ['a' , 'b'] as const // readonly ["a", "b"] type Name = typeof names[number] // "a" | "b" const arr = names.map(n => { // n is of type: "a" | "b" r

有没有一种不用“as”的方法

const names = ['a' , 'b'] as const // readonly ["a", "b"]
type Name = typeof names[number]  // "a" | "b"

const arr = names.map(n => {
    // n is of type: "a" | "b"
    return {[n]: 'smth'}
})


/*
 Array is of type:
 {
    [x: string]: string;
 }[]

 How to make it of type:
  {
    [x in Name]: string;
 }[]
*/