apache / apache/arrow-js

[JS] Strong typing for builders

Open
#90 2 comments 0 reactions 1 assignee Claimed by @Divyanshu-s13 View on GitHub
Type: bug
Dominant language
TypeScript
Stars
112
Forks
23
Avg merge
21h 18m
Merged PRs (30d)
8

Description

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](https://github.com/apache/arrow/blob/25e0dd488ab60417f8f453f648e6ecfeb058f01e/js/src/row/struct.ts#L28). It seems that instead of or `|` the type is created with `{}&{`}, and this causes the editor to complain.

Let's look at an example.
```javascript

interface ValueType extends arrow.TypeMap {
time: arrow.TimestampMillisecond,
value: arrow.Float64,
}
type Value = {
time: number,
value: number,
}
const children: (arrow.Field | arrow.Field)[] = [
new arrow.Field('time', new arrow.TimestampMillisecond()),
new arrow.Field('value', new arrow.Float64()),
]
const valueDataType: arrow.Struct = new arrow.Struct(children) // forcing the Struct type here - without it the error message is the same and will just show instead of
const builder: arrow.StructBuilder = 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'.
Type 'Value' is missing the following properties from type 'StructRow': toArray, toJSON, [kRowIndex], [kParent], [Symbol.iterator]
*/
```
To prevent editor error highlights, I have to obfuscate the builder type.
```javascript

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

**Reporter**: [Teodor Kostov](https://issues.apache.org/jira/browse/ARROW-16750)

**Note**: *This issue was originally created as [ARROW-16750](https://issues.apache.org/jira/browse/ARROW-16750). Please see the [migration documentation](https://github.com/apache/arrow/issues/14542) for further details.*

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.