create type as values of list typescript

function stringLiterals<T extends string>(...args: T[]): T[] { return args; }
type ElementType<T extends ReadonlyArray<unknown>> = T extends ReadonlyArray<infer ElementType> ? ElementType : never;

const values = stringLiterals('A', 'B');
type Foo = ElementType<typeof values>;

const v1: Foo = 'A' // This should work
const v2: Foo = 'D' // This should give me an error since 'D' doesn't exist in values

4.63
8
VJGOP 95 points

                                    //is not strict mode
let endedCoord: {x: number, y: number} = {
  	x: -1,
  	y: -1,
}

4.63 (8 Votes)
0
4
5
Sekhar3121 70 points

                                    // You can create your list as enums
enum statuses {
  SETUP,
  STARTED,
  FINISHED
}

// Creates known string type
// 'SETUP' | 'STARTED' | 'FINISHED'
type StatusString = keyof typeof statuses

// JobStatus.status must match 'SETUP' | 'STARTED' | 'FINISHED'
export type JobStatus = {
  status: StatusString
}

4 (5 Votes)
0
3.7
10

                                    enum Color {
  Red = &quot;red&quot;,
  Green = 2,
  Blue = 4,
}
let c: Color = Color.Green;Try

3.7 (10 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
array typescript of number typescript listas list typescript angular how to create list in typescript array of arrays typescript type of item in an array typescript typescript tyoe list declare list in typescript string list in typescript typescript create list of type typescript type array with any element how to define a type of list of number in typescript list of types typescript typescript string list type typescript type from array items can we use List in Typescirpt typescript type one level array typescript list of typescript one of list how to define a list in typescript list of array typescript list of items type typescript typescript array array of any typescript one of the array items list methods in typescript typescripts list list of types in typescript typescript one of the values of array get the list of possible types in typescript get the list of types in typescript how to make a list of a certain type in typescript typescript oneof value from array typescript array array typescript type of item in array typescript type of list list typeof {} typescript which type is list in typescript which type is list in ts which type is lists in ts typescript element type list typescript array of numer declare list of type in typescript typescript type array of arrays how to declare a list of a type in typescript list of typehints in typescript list of typehint in typescript array inside array typescript typescript type one of array typescript array of arrays type typescript listjs typescript one of array element in list typescript list of typescript typescript takes in an array of TYPE typescript array of anything data types list in typescript ts list typescript one of array element liste in typescript typescript list types typescript react list types Lists in TypeScript typescript type element one of array value how to make list in typescript array in array in typescript typescript types list typescript oneof array array of items of array typescript ts list type new list typescript any array typescript typecript list typescript create list typescript array of arrays typescript number array type list typescript array of any typescript typescript array list typescript type array of array typescript list of items list of object typescript typescript array of array making list in typescript typescript type list typescript data type list typeof one element of array typescript how to make a variable type list in ts type of an array of arrays typescript list data type in typescript how to type a list in typescript array inside an array typescript list type in typescript typescript -1 array typescript List type typescrpt create list array of array typescript typescript list tyep typescript array of any typescript array type List&lt;&gt; typescript typescript list of types list from array typescript lists typescript define a list type typescript list type in ts list of type list in ts typescript list definition typescript one of array values ts type of typed % type in typescript list in typescript typescript get object from Type ts array type list of list typescript typescript type from array create a list typescript typescript return modified object typescript define types any typescript add types to object obj datatype in typescript how to type objects typescript typescript define object of strings typescript type object of strings typescript object typescript type object typescrip object type how to initialize number in angular typescript typeof one of array typescript {} | type Object.values(Colors); typescript declare object inside object typescript object type in typescript in argument typescript set type of object create type as values of list typescript typescript type from object values typescript any property on object define typescript value in object typescript object js types of objects typescript typin object variable typescript typescript object to type how to use typescript types in object typescript object type that accepts anything object property that gives value typescript get type of object typescript not string type entire object typescript set string property of array typescript define object type typescript typescript define type as object properties javascript object in ts objects typescript one from array ts how to type an object in typescript typescript is string an object typescript of object stype typescript define object type typescript object string and number how to create a object of specific type in typescript declare type typescript set object type typescript type script [string]: string how to create an object of a type in typescript typescript object like type type typescript array create x objects typescript type of object how to declare object type in typescript type en typescript typescript and objects ts type object with field array of string type ts typescript type for object string define object typescript create an object of given type in typescript typescrip object methiods typescript objects how to determine types in objects in typescript typescript type for object properties typescript object with property typescript object attribute with type typescript define array numbers return type define a object in typescript typescript get object type typescript @property types typescript documentation string array property typescript object props typescript define allowed types typscript array typescript how to declare an object typescript craete type object typed object typescript typescript initial value type typescript type 'string' is not '&quot;x&quot;' define types in objects typescript define types in objects typsecript list of a type in typescript typescrip object of funcions scalar types typescript typescript scalar typescript type declaration object typescript declare object with type Type assertion in TypeScript object typescript how to add typescript types to object values list of model in typescript .tobject() in typescript typescript type of object value typescript object type of value array string object typescript create a type that could be any values from another type Typescript typescript define object typescript Object&lt;T&gt; in typescript declaring array typescript make different type of object using typescript option field in object type typescript option field in objecttype typescript typescript object with properties from other type object property type typescript typescript type without custom object typescript struct list typescript type any in object set types of object properties typescript any object type typescript typescript define type array of number how to define an object javascript typescript how to define types in typescript What does '{data:value}[]' mean in typescript object in typescript type of object in typescript object of string typescript &quot;&lt;Type&gt;&quot; in typescript typescript array annotation typescript Figure object type typescript ts object collection of types typescript typescript array value type string ts type object on declaration typescript type object typescript define all types of object as string typescript object method type this The Different Types of Typescript types typescript type define object properties typescript Set object type in object typescript defining types in object how to create a list with typescript different type of types available in typescript typescript custom object return type for in with types typescript typescript define object parameter typescript object paramater typescript force object tpye type object typescript typescript typing object typescript data object of objects typescript data object typescript object not string tpe typescript using ! on typescript object notation typescript string for object parameter objects const ts typescript or types type in typescript assign type to object typescript add type to object typescript type an object typescript typescript object typescript vector defining types in typescript typescript declare object property as function define type in object type script typescript object properties object type in typescript typescript with as part type typescript what is a type in typescript typescript object declare type and assign value typescript in objects typescript defining objects typescript declare object what is !!!value in typescript typescript multiple types input properties method object give types to object what does it do { item }: { item: object } in type script typescript typeof for array typescript js obj to ts create an object type typescript typescript object what are a i O s values how to declare a new type typescript typescript type css classes typescript type from array values typescript type from string array typescript type typescripts all types ts is string typescript declare type in object ts types typescript 5 possible strings initialize normal object with string key no type typescript type typescript simple cuote typescript typescript declare an object any type in typescript typescript type in object typescript object types typescript any object type list typescript typescript string|null[] typescript type array either string or null set object type as object all data types typescript object parameter typescript typescript reference object string declaring an arraynin typescript object of strings typescript ts object type typescript object type typescript create type from number create type from array typescript typescript list type fields for int in typescript typescript declare string array typescript a[] | b [] typescript list type typescript array declaration how to define array intype script array of strings typescript typescript type for integer what is value? in typescript typescript type from array of strings typescript type array string typescript type a variable typescript interface integer typescript array type string typescript array type typescript les array typescript typescript elements typescript lists write elements of list typescript typescript OR a list of strings type of array having string and other type typescript type array typescript+ typescript values in array get strings as array from a type in ts typescript one of array type typecriipt type from array one of array typescript typescript string[] typescript one of values in array string element number typescrtipt typscript list example ts array variable TS array typescript create array with defined types angular variable with type array array type object typescript array declaration typescript ts declare a list of strings ts to array type typescript object of arrays ts data structure declaration ts declare array of number array from type typescript typescript define array of strings typescript any array typescript give array of type any typescript declare arra ts initialize string array typescript define array of number typescript declare array of number how to specify array type in typescript typescript arrat declare a list type typescript list ts type of array typescript typescipt array array&lt;&gt;() typescript typescript list collection typescript typed array typescript string or nu,ber array typescript type in value array using [] in typescript typerscript define an array variable type script arrays typescript set variable to array arrays typescript typescript declare an array type an array typescript type array for string array of type string to array typescript define array of two types typescript how to declare variables as array string type ? array of type any array i typescript assign variable in array typescript typescript declare array of numbers how to write let array typescript typescript define an array of numbers or strings ts array of strings how to assign 2nd and 3rd of an array ts declare table typescript value in table typescript function integer array typescript create string array typescript typescript number[] typescript array of strings and numbers new array of type typescript typescript list define a list in typescript new array type typescript ts in array list js typescript typescript type for list of strings typescript set of strings angular set variable for on item of array typescript new string [] type script list typescript number or string array typescript string or number array typescript handling listitems array type angular typescirpt array typescript asing number to Element typescript array variable declaration declare an int array typescript declare an array typescript typescript list for lista typescript typescript declare type array of strings list type in angular list of string in typescript typescript array of strings as type adeclare array of strings typescript create array from type typescript ts is object in list array declaration ts typescript deflatting array typing array typescript number array in typescript typescript array of typeskript array of two numbers typescript where in array typescript list example typescript for array typescript array typescript declare array of strings for class typescript array data type typescript array of strings to type create an array of string in typescript typescprit array how to compose a new array type in typescript typescrip declare array any type in array typescript type string or array typescript set trype string or array typescript types from array string typescript list string arraylist in typescript typescript list array in typescript array\ in typescript type array of typescript how to write list with types in typescript typescript string from array typescrupt type array array type field typescript class typescript should have list array of any type typescript typescript one of array of strings create type from each element of array typescript string value one of array
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source