Похожие чаты

Is it possible to create a string union type from

an array of objects?
Something like the keyof type operator. maybe first I need to transform my array to an object? 🤔

5 ответов

9 просмотров

Example?

Misan- Автор вопроса
Darvesh 🍀
Example?

Something like this: const specFiles = (config) => { const getSpecFiles = () => ['whatever', 'example'] const getReleaseChannelSpecFiles = async <K extends string>(name: string): Promise<Record<K, string[]>> => Object.fromEntries( await Promise.all(config.releaseChannelsFilter.map(async channel => [channel.name, await getSpecFiles(name + channel.filter)] )) ) return { getReleaseChannelSpecFiles } } specFiles({ releaseChannels: [ { name: 'alpha', filter: 'm-' }, { name: 'beta', filter: 'b-' }, { name: 'stable', filter: '-' }, ] })

Yes

Misan- Автор вопроса

Oh I found the solution: https://stackoverflow.com/questions/60496276/typescript-derive-union-type-from-array-of-objects const articles = [ { articlenumber: '10-20-30' }, { articlenumber: '10-20-40' }, { articlenumber: '10-70-50' }, ] as const type Articlenumber = typeof articles[number]['articlenumber'] 👍

Похожие вопросы

Обсуждают сегодня

Карта сайта