Skip to content Skip to sidebar Skip to footer

Flow-type For Dynamic Dependencies Of Possible Values Of 'a' Attribute (array) On Values 'b' ([prop: String]: Any)

I have next type definition: type $Schema = { type?: 'object' | 'string' | 'number' | 'array', properties?: { [key: string]: $Schema }, additionalProperties?: boolean, rang

Solution 1:

You can try to use generic + $Keys<...>, like this:

type $Schema<T: {[key: string]: $Schema<*>}> = {
  type?: 'object' | 'string' | 'number' | 'array',
  properties?: T,
  additionalProperties?: boolean,
  range?: [number, number],
  required?: Array<$Keys<T>>
} 

and check schema:

const testSchema: $Schema<*> = {
  properties: {
    foo: {
      type: 'object',
      properties: {
        bar: {
          type: 'string'
        }
      },
      required: ['buz']
    }
  },
  required: ['foo']
}

Repl: https://flow.org/try/#0PTAEAEDMBsHsHcBQiAuBPADgU1AEgMoDGAFlgLYCGAPACoBcoA3gNoDWWaDAzigE4CWAOwDmAXQYES5agCoAfAF85oALxNEoUOmwB+BgHJYAIwBWWQin2gAPqH08BIq7f2CArmSNZezuxV68FGj6ADQaoBi8sNi8KPxYXHqgNGGaFAAm6fxxsIIU0AAKUTFxCUlGsLDQWBSCqaCBIlhJzO6e3iGgbV68ovW8WACObvwD6UkAggFBVLgA0hxctHJyiAqgyIS5PFoJKESklBIH0lTyquqakdHepVwMjOGakJUPT5pamFgGxmYWoe8rsVbvF7pcPhCjP43hDYZ9sAYHEJhPpAR8FGiFPUIQNhqMsOkGMx9EY3AAvfSid4YzRY8K4kZjIn6F6wSlrIA

Post a Comment for "Flow-type For Dynamic Dependencies Of Possible Values Of 'a' Attribute (array) On Values 'b' ([prop: String]: Any)"