Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(DataArray): warn on default data type #3183

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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