Skip to content

[JS] Strong typing for builders #90

@asfimport

Description

@asfimport

I've been obfuscating the builder types in my application to clear the editor issue highlights. However, it seems that the root cause is the way the StructRowProxy type is created. It seems that instead of or | the type is created with {}&{}, and this causes the editor to complain.

Let's look at an example.

interface ValueType extends arrow.TypeMap {
  time: arrow.TimestampMillisecond,
  value: arrow.Float64,
}
type Value = {
  time: number,
  value: number,
}
const children: (arrow.Field<arrow.DateMillisecond> | arrow.Field<arrow.Float64>)[] = [
  new arrow.Field('time', new arrow.TimestampMillisecond()),
  new arrow.Field('value', new arrow.Float64()),
]
const valueDataType: arrow.Struct<any> = new arrow.Struct<ValueType>(children) // forcing the Struct type here - without it the error message is the same and will just show <any> instead of <ValueType>
const builder: arrow.StructBuilder<ValueType, null | undefined> = arrow.makeBuilder({ type: valueDataType, nullValues: [null, undefined] })
...
const add = (value: Value) => builder.append(value)
/*
Argument of type 'Value' is not assignable to parameter of type 'StructRowProxy<ValueType>'.
  Type 'Value' is missing the following properties from type 'StructRow<ValueType>': toArray, toJSON, [kRowIndex], [kParent], [Symbol.iterator]
*/

To prevent editor error highlights, I have to obfuscate the builder type.

const builder: arrow.Builder = arrow.makeBuilder({ type: valueDataType, nullValues: [null, undefined] })

Reporter: Teodor Kostov

Note: This issue was originally created as ARROW-16750. Please see the migration documentation for further details.

Metadata

Metadata

Assignees

Labels

Type: bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions