Skip to content

Commit

Permalink
fix(DataArray): warn on default data type
Browse files Browse the repository at this point in the history
  • Loading branch information
floryst committed Dec 5, 2024
1 parent 34d5078 commit ba39aae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/Common/Core/DataArray/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ export function extend(

/**
* Method use to create a new instance of vtkDataArray
*
* If the provided `values` is a plain Array and `dataType` is not explicitly provided,
* then the vtkDataArray data type will be a Float32Array.
*
* @param {object} [initialValues] for pre-setting some of its content
*/
export function newInstance(initialValues?: object): vtkDataArray;
Expand Down
9 changes: 9 additions & 0 deletions Sources/Common/Core/DataArray/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,15 @@ const DEFAULT_VALUES = {
export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);

if (
Array.isArray(initialValues.values) &&
initialValues.dataType === undefined
) {
console.warn(
'vtkDataArray.newInstance: no dataType provided, converting to Float32Array'
);
}

if (!model.empty && !model.values && !model.size) {
throw new TypeError(
'Cannot create vtkDataArray object without: size > 0, values'
Expand Down

0 comments on commit ba39aae

Please sign in to comment.