Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

typescript one of array

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
Comment

PREVIOUS NEXT
Code Example
Typescript :: how to restrict alphabets in input field in angular 
Typescript :: c# check list of objects for value 
Typescript :: create react app with redux and typescript 
Typescript :: get one property from list of objects linq 
Typescript :: how to get child element li beautifulsoup 
Typescript :: html table to csv 
Typescript :: angular rxjs 
Typescript :: c# compare two objects for changes 
Typescript :: sweetalert2 
Typescript :: typeorm delete date column 
Typescript :: gamemanager unity resets after reloading scene 
Typescript :: data binding lwc multiple 
Typescript :: inno add exe in service 
Typescript :: merge to datasets in r 
Typescript :: coldfusion arrayLast 
Typescript :: nest js response timeout 
Typescript :: change field name relation typeorm 
Typescript :: div resize event typescript 
Typescript :: gettime is not a function typescript 
Typescript :: how to load events from an api in table_calendar flutter flutter 
Typescript :: loop trhough list of lists in python and find single elements 
Typescript :: typescript module 
Typescript :: c# merge two lists different types 
Typescript :: typeorm transaction example 
Typescript :: type to string typescript 
Typescript :: disable srr svelteKit 
Typescript :: typescript equals string 
Typescript :: acceso a etiqueta o elemento # en agnular 
Typescript :: No Apache installation can be found. Set the MOD_WSGI_APACHE_ROOTDIR environment to its location. 
Typescript :: can we do system testing at any stage 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =