For simple array members like that, you can use JSON.parse.

var array = JSON.parse("[" + string + "]");

This gives you an Array of numbers.

[0, 1]

If you use .split(), you'll end up with an Array of strings.

["0", "1"]

Just be aware that JSON.parse will limit you to the supported data types. If you need values like undefined or functions, you'd need to use eval(), or a JavaScript parser.


If you want to use .split(), but you also want an Array of Numbers, you could use Array.prototype.map, though you'd need to shim it for IE8 and lower or just write a traditional loop.

var array = string.split(",").map(Number);
Answer from I Hate Lazy on Stack Overflow
๐ŸŒ
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. const names: string[] = []; names.push("Dylan"); // no error // names.push(3); // Error: Argument of type 'number' is not assignable to parameter of type 'string'. Try it Yourself ยป
Discussions

How to convert typescript types of strings to array of strings?
I've this type: type myCustomType = "aaa" | "bbb" | "ccc"; I need to convert it to an array like this: ["aaa", "bbb", "ccc"] How can I do this in typescript? More on stackoverflow.com
๐ŸŒ stackoverflow.com
angular - Converting a string into an array in Typescript? - Stack Overflow
I'm using Angular 4 and a Spring ... the toString of a List of messages. The problem is that when I receive the exception response and extract the message, instead of being treated like an Array of strings, it's treated as a single string in the format of: "[message 1, message 2]" Is there a way in typescript to easily ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
What is {[key: string]: string} and how do I turn it into an array?
It's an object with both keys and values being of type string. Object.values(thisThing) should give you an array of values. edit: This type is an equivalent of Record More on reddit.com
๐ŸŒ r/typescript
10
13
January 24, 2023
How to define an array of strings in TypeScript interface? - Stack Overflow
TypeScript supports arrays, similar to JavaScript. There are two ways to declare an array: Using square brackets. This method is similar to how you would declare arrays in JavaScript. let fruits: string[] = ['Apple', 'Orange', 'Banana']; More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ String โ€บ split
String.prototype.split() - JavaScript - MDN Web Docs
The split() method of String values takes a pattern and divides this string into an ordered list of substrings by searching for the pattern, puts these substrings into an array, and returns the array.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ typescript โ€บ typescript_array_tostring.htm
TypeScript - Array toString()
Returns a string representing the array. var arr = new Array("orange", "mango", "banana", "sugar"); var str = arr.toString(); console.log("Returned string is : " + str );
๐ŸŒ
Bacancy Technology
bacancytechnology.com โ€บ qanda โ€บ javascript โ€บ how-to-convert-a-string-to-an-array-with-javascript-typescript
How to Convert a String to an Array in JavaScript/TypeScript
August 27, 2024 - /\d+\.\s/ is a regex pattern that matches one or more digits (\d+), followed by a dot (\.), and a space (\s). The split() method separates the string into an array based on this regex pattern.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ typescript โ€บ typescript_string_split.htm
TypeScript - String split()
This method splits a String object into an array of strings by separating the string into substrings. The split method returns the new array. Also, when the string is empty, split returns an array containing one empty string, rather than an empty
Find elsewhere
๐ŸŒ
SamanthaMing
samanthaming.com โ€บ tidbits โ€บ 83-4-ways-to-convert-string-to-character-array
4 Ways to Convert String to Character Array in JavaScript | SamanthaMing.com
The key there is "copies all enumerable own properties". So what we're doing here Object.assign([], string) it copying ALL of our string properties over to our new array. Which means we have an Array PLUS some string methods. This is more evident if we use the TypeScript Playground.
๐ŸŒ
DEV Community
dev.to โ€บ mehmehmehlol โ€บ from-string-to-array-to-string-f67
From String to Array to String - DEV Community
April 23, 2021 - On the other hand, if there is only one element in the array, the single item will be returned as a string without separators, and if there are no elements, an empty string is returned. As mentioned, including an argument for the separator parameter is optional if you want the elements to be joined with a comma.
๐ŸŒ
Tutorial Teacher
tutorialsteacher.com โ€บ typescript โ€บ typescript-array
TypeScript Arrays
TypeScript supports arrays, similar to JavaScript. There are two ways to declare an array: 1. Using square brackets. This method is similar to how you would declare arrays in JavaScript. let fruits: string[] = ['Apple', 'Orange', 'Banana'];
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ string-to-array-in-javascript
JavaScript - Convert String to Array - GeeksforGeeks
August 5, 2025 - The Array.from() method can convert a string into an array of characters. This method is especially useful if you want to create an array from an iterable object, like a string, without needing to specify a separator.
๐ŸŒ
Total TypeScript
totaltypescript.com โ€บ array-types-in-typescript
Array<T> vs T[]: Which is better? | Total TypeScript
January 14, 2025 - When you're declaring an array type in TypeScript, you've got one of two options: Array<T> or T[]. Dominik (@TKDodo on Twitter), one of the maintainers of React Query, recently posted an article on which option you should choose.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ typescript โ€บ how-to-create-array-of-string-in-typescript
How to Create Array of String in TypeScript ? - GeeksforGeeks
August 5, 2025 - The fill method fills all the elements of an array with a static value, from a start index to an end index. This approach is useful when we want to initialize an array with repeated string values. ... Example: The below code add elements to the array using the TypeScript fill() method.
Top answer
1 of 4
383

TypeScript 3.4+

TypeScript version 3.4 has introduced so-called **const contexts**, which is a way to declare a tuple type as immutable and get the narrow literal type directly (without the need to call a function like shown below in the 3.0 solution).

With this new syntax, we get this nice concise solution:

const furniture = ['chair', 'table', 'lamp'] as const;
type Furniture = typeof furniture[number];

More about the new const contexts is found in this PR as well as in the release notes.

TypeScript 3.0+

With the use of generic rest parameters, there is a way to correctly infer string[] as a literal tuple type and then get the union type of the literals.

It goes like this:

const tuple = <T extends string[]>(...args: T) => args;
const furniture = tuple('chair', 'table', 'lamp');
type Furniture = typeof furniture[number];

More about generic rest parameters

2 of 4
22

This answer is out of date; see @ggradnig's answer.

The best available workaround:

const furnitureObj = { chair: 1, table: 1, lamp: 1 };
type Furniture = keyof typeof furnitureObj;
const furniture = Object.keys(furnitureObj) as Furniture[];

Ideally we could do this:

const furniture = ['chair', 'table', 'lamp'];
type Furniture = typeof furniture[number];

Unfortunately, today furniture is inferred as string[], which means Furniture is now also a string.

We can enforce the typing as a literal with a manual annotation, but it brings back the duplication:

const furniture = ["chair", "table", "lamp"] as ["chair", "table", "lamp"];
type Furniture = typeof furniture[number];

TypeScript issue #10195 tracks the ability to hint to TypeScript that the list should be inferred as a static tuple and not string[], so maybe in the future this will be possible.

๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ typescript โ€บ typescript_array_join.htm
TypeScript - Array join()
TypeScript - null vs. undefined ... separator โˆ’ Specifies a string to separate each element of the array.
๐ŸŒ
TypeScript
typescriptlang.org โ€บ docs โ€บ handbook โ€บ 2 โ€บ everyday-types.html
TypeScript: Documentation - Everyday Types
string[] is an array of strings, and so on). You may also see this written as Array<number>, which means the same thing. Weโ€™ll learn more about the syntax T<U> when we cover generics. Note that [number] is a different thing; refer to the section on Tuples. TypeScript also has a special type, any, that you can use whenever you donโ€™t want a particular value to cause typechecking errors.