0

How would I go about making it so Typescript defaults to a certain type if the property isn't defined in the interface? For example:

export interface MyInterface {
  Parent: Instance,
  Name: string,
  __Connections: {
    [x: string]: Signal
  }
  Children: {
    [x: string]: Instance
  },
  Creatable: true,
  [default]: Instance // if the type isn't defined in this interface, default to Instance
}
TypeChecked
  • 91
  • 1
  • 1
  • 5
  • `[default]: Instance` -> `[default: string]: Instance` just like the other index signatures you have. – VLAZ Oct 31 '21 at 19:07
  • When I do that, it tells me that my other properties are not assignable to Instance. – TypeChecked Oct 31 '21 at 19:10
  • This isn't currently possible in TypeScript; see [this question](https://stackoverflow.com/questions/61431397/how-to-define-typescript-type-as-a-dictionary-of-strings-but-with-one-numeric-i) and its answer for approaches and workarounds. – jcalz Oct 31 '21 at 19:46
  • Unfortunately I can't use that approach, but thanks for the help! – TypeChecked Oct 31 '21 at 20:44

0 Answers0