Chore: improve types (#78126)

* fix some types

* more type updates

* some more fixes

* more changes

* string instead of unknown

* more like original logic

* remove outdated comment

* update betterer
This commit is contained in:
Ashley Harrison
2023-11-16 12:39:12 +00:00
committed by GitHub
parent b0448b92e5
commit 2c0c51a0df
43 changed files with 135 additions and 236 deletions
@@ -143,7 +143,7 @@ export function decodeFieldValueEntities(lookup: FieldValueEntityLookup, values:
*/
export function decodeFieldValueEnums(lookup: string[], values: FieldValues) {
for (let i = 0; i < values.length; i++) {
values[i] = lookup[values[i] as number];
values[i] = lookup[Number(values[i])];
}
}
@@ -240,7 +240,9 @@ export function dataFrameToJSON(frame: DataFrame): DataFrameJSON {
name: frame.name,
fields: frame.fields.map((f) => {
const { values, nanos, state, display, ...sfield } = f;
delete (sfield as any).entities;
if ('entities' in sfield) {
delete sfield.entities;
}
data.values.push(values);
if (nanos != null) {
@@ -13,7 +13,7 @@ import { FunctionalVector } from '../vector/FunctionalVector';
* @typeParam T - Type of object stored in the DataFrame.
* @beta
*/
export class DataFrameView<T = any> extends FunctionalVector<T> {
export class DataFrameView<T extends object = any> extends FunctionalVector<T> {
private index = 0;
private obj: T;
readonly fields: {
@@ -22,7 +22,7 @@ export class DataFrameView<T = any> extends FunctionalVector<T> {
constructor(private data: DataFrame) {
super();
const obj = {} as unknown as T;
const obj = {} as T;
const fields = {} as any;
for (let i = 0; i < data.fields.length; i++) {
@@ -34,14 +34,14 @@ export class DataFrameView<T = any> extends FunctionalVector<T> {
fields[field.name] = field;
const getter = () => field.values.get(this.index); // .get() to support all Vector types
if (!(obj as any).hasOwnProperty(field.name)) {
if (!obj.hasOwnProperty(field.name)) {
Object.defineProperty(obj, field.name, {
enumerable: true, // Shows up as enumerable property
get: getter,
});
}
if (!(obj as any).hasOwnProperty(i.toString())) {
if (!obj.hasOwnProperty(i.toString())) {
Object.defineProperty(obj, i, {
enumerable: false, // Don't enumerate array index
get: getter,
@@ -488,7 +488,7 @@ export function getStreamingFrameOptions(opts?: Partial<StreamingFrameOptions>):
// converts vertical insertion records with table keys in [0] and column values in [1...N]
// to join()-able tables with column arrays
export function transpose(vrecs: any[][]) {
export function transpose(vrecs: unknown[][]) {
let tableKeys = new Set(vrecs[0]);
let tables = new Map();
@@ -33,10 +33,11 @@ function convertTableToDataFrame(table: TableData): DataFrame {
const fields = table.columns.map((c) => {
// TODO: should be Column but type does not exists there so not sure whats up here.
const { text, type, ...disp } = c as any;
const values: unknown[] = [];
return {
name: text?.length ? text : c, // rename 'text' to the 'name' field
config: (disp || {}) as FieldConfig,
values: [] as unknown[],
values,
type: type && Object.values(FieldType).includes(type as FieldType) ? (type as FieldType) : FieldType.other,
};
});