0

Given the following type

type A = {
    foo: string
    bar: number
}

is it possible to create a mapped/conditional type such that

type APropertyNameList = MapToProperyNameList<A>

let l1: APropertyNameList = ["foo", "bar] //correct
let l2: APropertyNameList = ["foo", "boom"] //compile error
let l3: APropertyNameList = ["foo", "bar", "bar"] //compile error 2x bar
robkuz
  • 9,488
  • 5
  • 29
  • 50
  • Possible duplicate of [Get keys of a Typescript interface as array of strings](https://stackoverflow.com/questions/43909566/get-keys-of-a-typescript-interface-as-array-of-strings) – ford04 Sep 22 '20 at 12:48

1 Answers1

0
type A = {
    foo: string
    bar: number
}

type MyKeys<T> = (keyof T)[];

const l1: MyKeys<A> = ['foo', 'bar'] // Correct
const l2: MyKeys<A> = ['foo', 'boom'] // Error
Guilhermevrs
  • 2,094
  • 15
  • 15