an array of objects?
Something like the keyof type operator. maybe first I need to transform my array to an object? 🤔
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
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'] 👍
Обсуждают сегодня