Answer the question
In order to leave comments, you need to log in
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 //
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question