@wvw1

Как в TS сделать тип типо { id: number, [key in keys]: string } ???

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 //


Заранее спасибо большое!)
  • Вопрос задан
  • 135 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы