Answer the question
In order to leave comments, you need to log in
How to make type from array elements in typescript?
const arr = ['a', 'b', 'c'];
type MyType = 'a' | 'b' | 'c';
Answer the question
In order to leave comments, you need to log in
const arr = ['a', 'b', 'c'] as const;
type MyType = (typeof arr)[number];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question