Yes you can type your variables with a single type

// type data as an array of strings
const data: string[] = [];

// type data as an array of numbers
const data: number[] = [];

// type data as an array of objects
const data: object[] = [];

If you want to use a mix of types in your array, you can type it as any. But this may not be a good practise.

const data: any[] = [];

For more information about type in typescript, look here: Basic type documentation

For defining array with multiple types, look here: https://stackoverflow.com/a/29382420/1934484

Answer from Tomas Vancoillie on Stack Overflow
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Typed_arrays
JavaScript typed arrays - JavaScript | MDN
Int16Array | 32 | 0 | 2 | 0 | 4 | 0 | 6 | 0 | Int32Array | 32 | 2 | 4 | 6 | ArrayBuffer | 20 00 00 00 | 02 00 00 00 | 04 00 00 00 | 06 00 00 00 | You can do this with any view type, although if you set an integer and then read it as a floating-point number, you will probably get a strange result because the bits are interpreted differently.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript | MDN
Both the original and new array refer to the same object. That is, if a referenced object is modified, the changes are visible to both the new and original arrays. Primitive types such as strings, numbers and booleans (not String, Number, and Boolean objects): their values are copied into the ...
🌐
Built In
builtin.com › software-engineering-perspectives › javascript-array-typeof
JavaScript Typeof for Data Types: Array, Boolean and More | Built In
The typeof operator in JavaScript is used to check the data type of a variable in code. It can determine if a variable's data type is an array, boolean or other. Written by Dr. Derek Austin ...
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Data_structures
JavaScript data types and data structures - JavaScript | MDN
Variables in JavaScript are not directly associated with any particular value type, and any variable can be assigned (and re-assigned) values of all types: ... let foo = 42; // foo is now a number foo = "bar"; // foo is now a string foo = true; // foo is now a boolean
🌐
typescriptlang.org
typescriptlang.org › docs › handbook › 2 › everyday-types.html
TypeScript: Documentation - Everyday Types
The type names String, Number, and Boolean (starting with capital letters) are legal, but refer to some special built-in types that will very rarely appear in your code. Always use string, number, or boolean for types. To specify the type of an array like [1, 2, 3], you can use the syntax number[]; ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › TypedArray
TypedArray - JavaScript | MDN
It stores the number in binary like Uint8Array does, but when you store a number outside the range, it clamps the number to the range 0 to 255 by mathematical value, instead of truncating the most significant bits. All typed arrays except Int8Array, Uint8Array, and Uint8ClampedArray store each element using multiple bytes.
🌐
W3Schools
w3schools.com › js › js_arrays.asp
JavaScript Arrays
JavaScript does not support associative arrays. You should use objects when you want the element names to be strings (text). You should use arrays when you want the element names to be numbers.
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Number
Number - JavaScript | MDN
Creates Number objects. When called as a function, it returns primitive values of type Number. ... The smallest interval between two representable numbers. ... The maximum safe integer in JavaScript (253 - 1).
🌐
W3Schools
w3schools.com › js › js_typed_arrays.asp
JavaScript Typed Arrays
Typed arrays store elements of Fixed Types like 8-bit integers or 32-bit numbers. ... Typed Arrays were designed to provide an efficient way to handle binary data, unlike traditional JavaScript arrays which can hold elements of mixed data types.
🌐
Flow
flow.org › arrays
Arrays | Flow
The main advantage to using ReadonlyArray instead of Array is that ReadonlyArray's type parameter is covariant while Array's type parameter is invariant. That means that ReadonlyArray<number> is a subtype of ReadonlyArray<number | string> while Array<number> is NOT a subtype of Array<number | string>. So it's often useful to use ReadonlyArray in type annotations for arrays of various types of elements.
🌐
bitsofcode
bitsofco.de › javascript-typeof
"What's the typeof null?", and other confusing JavaScript Types | bitsofcode
Those two NaN values are not equal because they are not necessarily the same unrepresentable number. ... The typeof an array is an object. In JavaScript, arrays are technically objects; just with special behaviours and abilities. For example, arrays have a Array.prototype.length property, which will return the number of elements in the array.
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Grammar_and_types
Grammar and types - JavaScript | MDN
These are fixed values—not variables—that you literally provide in your script. This section describes the following types of literals: ... An array literal is a list of zero or more expressions, each of which represents an array element, enclosed in square brackets ([]).
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › typeof
typeof - JavaScript | MDN
(logical NOT) operator are equivalent to Boolean() // Symbols typeof Symbol() === "symbol"; typeof Symbol("foo") === "symbol"; typeof Symbol.iterator === "symbol"; // Undefined typeof undefined === "undefined"; typeof declaredButUndefinedVariable === "undefined"; typeof undeclaredVariable === "undefined"; // Objects typeof { a: 1 } === "object"; // use Array.isArray or Object.prototype.toString.call // to differentiate regular objects from arrays typeof [1, 2, 4] === "object"; typeof new Date() === "object"; typeof /regex/ === "object"; // The following are confusing, dangerous, and wasteful. Avoid them. typeof new Boolean(true) === "object"; typeof new Number(1) === "object"; typeof new String("abc") === "object"; // Functions typeof function () {} === "function"; typeof class C {} === "function"; typeof Math.sin === "function"; js ·
🌐
TypeScript
typescriptlang.org › docs › handbook › 2 › objects.html
TypeScript: Documentation - Object Types
Whenever we write out types like number[] or string[], that’s really just a shorthand for Array<number> and Array<string>. ... Much like the Box type above, Array itself is a generic type. ... Modern JavaScript also provides other data structures which are generic, like Map<K, V>, Set<T>, and Promise<T>. All this really means is that because of how Map, Set, and Promise behave, they can work with any sets of types.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-data-types
JavaScript Data Types - GeeksforGeeks
They are fundamental as nearly everything in JavaScript is an object. ... An Array is a special kind of object used to store an ordered collection of values, which can be of any data type.
Published   April 24, 2019
🌐
Medium
medium.com › @julienetienne › different-types-of-arrays-in-javascript-and-when-to-use-them-77f7843b71de
Different Types of Arrays in JavaScript + When to Use Them | by Julien Etienne | Medium
February 8, 2024 - In Golang, this would be a Slice, Python has List and JavaScript has Array. There are many nuances regarding Arrays in JS: with holes, without, is an Object etc. This is my rule of thumb: If it’s not going to be beneficial don’t obsess about it · With that said, I want to touch on just the most important aspects of Arrays in JS. If you don’t already know, you can type-check arrays using Array.isArray() which I tend to destructure using const { isArray } = Array.