Teodor Kostov created ARROW-16750:
-------------------------------------
Summary: [JS] Strong typing for builders
Key: ARROW-16750
URL: https://issues.apache.org/jira/browse/ARROW-16750
Project: Apache Arrow
Issue Type: Bug
Components: JavaScript
Affects Versions: 9.0.0
Reporter: Teodor Kostov
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.
{code:javascript}
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]
*/
{code}
To prevent editor error highlights, I have to obfuscate the builder type.
{code:javascript}
const builder: arrow.Builder = arrow.makeBuilder({ type: valueDataType,
nullValues: [null, undefined] })
{code}
--
This message was sent by Atlassian Jira
(v8.20.7#820007)