W
W
wvw12022-03-05 01:20:23
typescript
wvw1, 2022-03-05 01:20:23

How to make type like { id: number, [key in keys]: string } in TS???

const keys = [
  'id',
  'firstName',
  'lastName',
  'email',
  'phone',
  'street',
  'city',
  'state',
  'zip',
  'description',
] as const

type Keys = typeof keys[number] // 'id' | 'firstName' | ...
type KeysWithoutId = Exclude<Keys, 'id'>

type Item = {
  id: number, // !!! A mapped type may not declare properties or methods.ts(7061)
  [key in KeysWithoutId]: string //


Thank you very much in advance!)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question