You cannot test for string[] in the general case but you can test for Array quite easily the same as in JavaScript https://stackoverflow.com/a/767492/390330 (I prefer Array.isArray(value)).

If you specifically want for string array you can do something like:

if (Array.isArray(value)) {
   var somethingIsNotString = false;
   value.forEach(function(item){
      if(typeof item !== 'string'){
         somethingIsNotString = true;
      }
   })
   if(!somethingIsNotString && value.length > 0){
      console.log('string[]!');
   }
}

In case you need to check for an array of a class (not a basic type)

if(items && (items.length > 0) && (items[0] instanceof MyClassName))

If you are not sure that all items are same type

items.every(it => it instanceof MyClassName)
Answer from basarat on Stack Overflow
🌐
TypeScript Tutorial
typescripttutorial.net › home › typescript tutorial › typescript array type
TypeScript Array Type
August 24, 2024 - In this example, we extract the ... infers the type of the skill variable to string as shown in the output. TypeScript arrays have the same properties and methods as JavaScript arrays....
🌐
TypeScript
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[]; ...
Discussions

Test for array of string type in TypeScript - Stack Overflow
Instead of using negation in two ... => typeof value === 'string') 2020-07-24T09:15:35.593Z+00:00 ... @SebastianVittersø Thanks for the NICE suggestion. I updated my answer. 2020-07-24T09:31:37.493Z+00:00 ... will not stop the foreach. So the function will return true even if the array does contain ... More on stackoverflow.com
🌐 stackoverflow.com
In Typescript how do you get an element type from an array type, when the array contains different element types? - Stack Overflow
We may think it's getting [number] ... parent type. Ergo: type InputType = (typeof input)[number];. PS: This should be the accepted solution @mastrolindus 2023-08-30T07:08:23.603Z+00:00 ... You can extract it by pointing at an array member, so while you are using the below code ... More on stackoverflow.com
🌐 stackoverflow.com
Deriving a type from fields of objects in an array
Don't type foo as a string but as string literals? Or maybe don't type a, b and c like that but use satisfies? More on reddit.com
🌐 r/typescript
5
2
August 19, 2023
How to get type from array of objects
type MyType = typeof myarr[number]["field1"]; More on reddit.com
🌐 r/typescript
9
16
August 19, 2022
🌐
Tutorial Teacher
tutorialsteacher.com › typescript › typescript-array
TypeScript Arrays
This method is similar to how you would declare arrays in JavaScript. let fruits: string[] = ['Apple', 'Orange', 'Banana']; 2. Using a generic array type, Array<elementType>. let fruits: Array<string> = ['Apple', 'Orange', 'Banana']; Both methods produce the same output. Of course, you can always initialize an array like shown below, but you will not get the advantage of TypeScript's type system.
🌐
Built In
builtin.com › software-engineering-perspectives › javascript-array-typeof
JavaScript Typeof for Data Types: Array, Boolean and More | Built In
Yes, typeof returns "undefined" for undeclared variables without throwing an error. Use Array.isArray() or Object.prototype.toString.call() to accurately check if a JavaScript variable is an array data type, since typeof returns "object" for arrays.
🌐
Graphite
graphite.com › guides › typescript-typeof-operator
TypeScript typeof operator - Graphite
When used with an array, typeof will return the type of the elements inside the array along with an array indicator ([]).
🌐
Bobby Hadz
bobbyhadz.com › blog › typescript-check-if-type-array
Check if a Value is an Array (of type) in TypeScript | bobbyhadz
Copied!const arr: string[] = ['bobby', 'hadz', 'com']; if (Array.isArray(arr)) { const isStringArray = arr.length > 0 && arr.every((value) => { return typeof value === 'string'; }); console.log(isStringArray); // 👉️ true }
Find elsewhere
🌐
TypeScript
typescriptlang.org › docs › handbook › 2 › indexed-access-types.html
TypeScript: Documentation - Indexed Access Types
Another example of indexing with an arbitrary type is using number to get the type of an array’s elements. We can combine this with typeof to conveniently capture the element type of an array literal:
🌐
Bobby Hadz
bobbyhadz.com › blog › typescript-array-element-type
Get the Element type from an Array type in TypeScript | bobbyhadz
Use a condition type with an infer declaration to infer the type of an element in the array. TypeScript will fill in the type of the element and we can return it in the true branch of the conditional type. index.ts · Copied!type ArrElement<ArrType> ...
🌐
Medium
medium.com › @mehdi.havaei77 › whats-the-meaning-of-typeof-array-number-in-typescript-7fa6b53120f0
What’s the meaning of typeof Array[number] in Typescript? | by Mehdi Havaei | Medium
September 29, 2023 - The type of the properties of T whose keys are of type K. So (Array<”apple” | “banana” | “peach”>)[number] means the types of the properties of Array<”apple” | “banana” | “peach”> whose keys are of type number, OR : the array elements of Array<”apple” | “banana” | “peach”>, or: ”apple” | “banana” | “peach” · The type T[K] is a lookup type which gets the type of the property of T whose key is K. In (typeof list)[number], you’re getting the types of the properties of (typeof list) whose keys are number.
🌐
TypeScript
typescriptlang.org › play › javascript › javascript-essentials › objects-and-arrays.ts.html
TypeScript: Playground Example - Objects and Arrays
TypeScript offers a way to declare an array readonly instead: Creates a type based on the shape of a purchase order: type PurchaseOrder = typeof purchaseOrder; // Creates a readonly array of purchase orders const readonlyOrders: readonly PurchaseOrder[] = [purchaseOrder]; // Yep!
🌐
Medium
medium.com › geekculture › 5-ways-to-judge-array-in-typescript-dfeb1d9c310b
5 Ways to Judge Array in TypeScript | by Zachary | Geek Culture | Medium
March 21, 2022 - When the call to if (isArray(testData)) passes, TypeScript will reduce the variable type to the concrete Array<unknown> type in the next branch scope, conversely, in the else branch, it will is not of type Array<unknown>. Ok, let’s take a look at the logic of the isArray method. This judgment logic is correct, but once the constructor of the array is modified, it is impossible to make a correct judgment. function isArray(arr: unknown): arr is Array<unknown> { return typeof arr === 'object' && arr?.constructor === Array; }const testData: unknown = [1, 2, 3]; // @ts-ignore testData.constructor = null; console.log(isArray(testData)); // false
🌐
Total TypeScript
totaltypescript.com › get-the-type-of-an-array-element
This Crazy Syntax Lets You Get An Array Element's Type | Total TypeScript
September 2, 2024 - Learn how to extract the type of an array element in TypeScript using the powerful `Array[number]` trick.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › isArray
Array.isArray() - JavaScript - MDN Web Docs
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015 · Array.isArray() checks if the passed value is an Array. It performs a branded check, similar to the in operator, for a private field initialized by the ...
🌐
Reddit
reddit.com › r/typescript › deriving a type from fields of objects in an array
r/typescript on Reddit: Deriving a type from fields of objects in an array
August 19, 2023 -

I want to create a type restricted to the values used by the objects in an array for a specific type.

I have it working, until I define a type for those objects in the array - then my type becomes just the type of the field in that type.

E.g.

const x = { foo: "foofy" } as const;
const y = { foo: "barfy" } as const;
const z = { foo: "bazfy" } as const;

const xyz = [x, y, z];

type XYZ = typeof xyz[number]["foo"];
// XYZ = "foofy" | "barfy" | "bazfy"

But adding a type:

type Fooey = { foo: string };

const a: Fooey = { foo: "foozy" } as const;
const b: Fooey = { foo: "barzy" } as const;
const c: Fooey = { foo: "bazzy" } as const;

const abc = [a, b, c];

type ABC = typeof abc[number]["foo"];
// ABC = string

Is there a way I can have my cake and eat it, here?

typescript playground

TIA!

🌐
Fjolt
fjolt.com › article › typescript-array-type
TypeScript Array Type
July 9, 2022 - If we have an array, we can define its type in TypeScript by using the notation type[]. For example, the below variable arrayType is expected to be an array of strings. ... This also conforms any future array items to that type.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › typeof
typeof - JavaScript - MDN Web Docs - Mozilla
January 8, 2026 - It's used in Object.prototype.toString(). const tag = value[Symbol.toStringTag]; if (typeof tag === "string") { return tag; } // If it's a function whose source code starts with the "class" keyword if ( baseType === "function" && Function.prototype.toString.call(value).startsWith("class") ) { return "class"; } // The name of the constructor; for example `Array`, `GeneratorFunction`, // `Number`, `String`, `Boolean` or `MyCustomClass` const className = value.constructor.name; if (typeof className === "string" && className !== "") { return className; } // At this point there's no robust way to get the type of value, // so we use the base implementation.
🌐
W3Schools
w3schools.com › typescript › typescript_arrays.php
TypeScript Arrays
TypeScript has a specific syntax for typing arrays. Read more about arrays in our JavaScript Array chapter.
🌐
GeeksforGeeks
geeksforgeeks.org › typescript › how-to-get-types-from-arrays-in-typescript
How To Get Types From Arrays in TypeScript? - GeeksforGeeks
September 26, 2024 - We will explore different methods to get the types from arrays in TypeScript using techniques such as typeof, Array<Type>, indexed access types, and tuple inference.