Pack formula resultType of object with property type of StringArray? (SOLVED)

I am attempting to return an object, with a property of type string[]

However, coda.ValueType.StringArray is not available for schema properties (only parameters)
And typing the items property of Arrays as coda.ValueType.String is not allowed either

pack.addFormula({
  resultType: coda.ValueType.Object,
  schema: coda.makeObjectSchema({
    properties: {
      property1: { type: coda.ValueType.String },
      arrayOfStrings: { type: coda.ValueType.Array, items: coda.ValueType.String }, // ".ValueType' is not assignable to type 'Schema'"
    },
  })
})

Instead, typing the example property arrayOfStrings as an array of objects (where the object has property of type string) works – but then there is an extra nested property myString

pack.addFormula({
  resultType: coda.ValueType.Object,
  schema: coda.makeObjectSchema({
    properties: {
      property1: { type: coda.ValueType.String },
      arrayOfStrings: {
        type: coda.ValueType.Array, items: coda.makeObjectSchema({
          properties: {
            myString: { type: coda.ValueType.String }, // works, but not ideal
          },
        })
      },
    },
  }),
})

Is there a way to type a resultType object’s property as an array of strings?

Thank you

Got it! The solution was to simply use coda.makeSchema() instead of coda.makeObjectSchema

pack.addFormula({
  resultType: coda.ValueType.Object,
  schema: coda.makeObjectSchema({
    properties: {
      property1: { type: coda.ValueType.String },
      arrayOfStrings: {
        type: coda.ValueType.Array, items: coda.makeSchema({ // makeSchema (not makeObjectSchema
          type: coda.ValueType.String,
        })
      },
    },
  }),
})

Glad you got it working! When inside an existing makeObjectSchema() call you actually don’t need to call the inner makeSchema():

let MySchema = coda.makeObjectSchema({
  properties: {
    property1: { type: coda.ValueType.String },
    arrayOfStrings: {
      type: coda.ValueType.Array, 
      items: { type: coda.ValueType.String },
    },
  },
});
1 Like

Ah I see my original mistake was that I tried to type the items with coda.ValueType.String directly rather than an object with a type property.

That is perfect! Thanks @Eric_Koleda