Похожие чаты

Is there a way in TypeScript to create an interface

for an object kind of like this? I want the value's name property to be the same as the key, e.g. {'a': {name: 'a'}}.

interface Foo {
[key: string]: {name: key};
}

8 ответов

1 просмотр
Banana- Автор вопроса

Bump

Banana
Bump

Would this work? type Foo<T> = { [K in keyof T]: { name: K } }

if you know the possible keys, you can use enum

Banana- Автор вопроса
Andrey Piskunov
screenshot if you know the possible keys, you can use enum

I don't, that's why I want the type safety when a new property is added to Foo to make sure the name property of the value is the same as the key.

Banana- Автор вопроса
𝙼
Would this work? type Foo<T> = { [K in keyof T]:...

If I try to use it, what type for T do I give to Foo when I try to use it?

What do you need this for?

Banana- Автор вопроса
Wojciech Pawlik
What do you need this for?

A project I'm contributing to. There's a large object that maps strings to values, but the name property of the value should equal the string key.

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

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

30 BCH videos in Hausa Language successfully delivered. In December 2023, I created a Flipstarter to produce Bitcoin Cash videos in the Hausa language for greater outreach an...
Munnir
5
читать файл максимально быстро? странный вопрос))
zamtmn
53
братва! где куличи брать?
Alöscha
25
тоесть, указав return eax, сгенерируется никому ненужная инструкция mov eax,eax ?
Aiwan \ (•◡•) / _bot
24
Посоветуйте пожалуйста аудио плеер для библиотеки mp3- FLAC на компьютере. На Винде пользовался Aimp, в том числе для конвертации. Много нужных команд было прямо в контекст...
Виктор Кузнецов
31
📢Join the FUNToken X Pamtoken Zealy Campaign - Let the Quest Begin!🔥 📢Attention, FUNToken Community! We're excited to announce the launch of our Zealy Campaign in collaborat...
OJohnny
7
Добрый день. Созданию отношения таблиц для учёта кораблей, их движения между точками (портами) согласно расписания. Терзают сомнения в правильном ли направлении двигаюсь 😅 1...
Aleksey
1
Is FXTL another frax ecosystem token? Why need fxtl when there is already fxs? Why cant I find a straight answer for this? Maybe thats why people think its all so complicated
MBD Tan
12
Компания Elif ищет менеджера проектов, который будет заниматься поиском и ведением новых проектов. Прежде чем приступить к работе, вам нужно пройти наш недельный курс, где вы ...
Elif
1
Hi guys , do we have update on voting?
HB
16
Карта сайта