0

Im trying to implement the following logic. "For specific attributes, I want to set a specific option. and for all other keys (strings) fallback to another type

I got the following code:

interface ProcedureValue {
    value: string
    title: string
}


export interface Procedure{
    procedure_creation_time: string
    [key :string]: ProcedureValue,
}

Im getting the following error:

Type error: Property 'procedure_creation_time' of type 'string' is not assignable to 'string' index type 'ProcedureValue'.

I have tried the following approaches:

  • Exclude type on the key
  • type | and &
  • extending interfaces

All of them fail. Is it possible to do so?

yoty66
  • 390
  • 2
  • 12
  • 1
    Not directly, no. There are a bunch of workarounds, none of which are great. See the [linked question](https://stackoverflow.com/questions/61431397/how-to-define-typescript-type-as-a-dictionary-of-strings-but-with-one-numeric-i) and its answers for more information. – jcalz Jul 18 '23 at 19:01

0 Answers0