#Dynamic keys and types in an object

5 messages · Page 1 of 1 (latest)

analog nebula
#

Hello all,
Is it possible to define some types to known keys in an object, and another type for unknown keys?

I tried this:

type Schemas = {
  $default?: Default;
  $extensions?: Extensions;
} & Record<string, Default>
``` 
But TS complains as soon as I write the $extensions value
#

I want $extensions to be of type "Extensions", and all the other keys to be of type Default

#

but it seems like I'm forced to do:

type Schemas = {
  $default?: Default;
  $extensions?: Extensions;
} & Record<string, Default | Extensions>

which is not correct because I know all the other keys can't be of type Extensions 😅

#

I would need something like Record<string except "$extensions", Default> :p