I have a function like this:
interface IUseTest {
settings: {
id: string
}
};
const useTest = (properties: IUseTest) => {
const { settings } = properties;
const test = (
item: {
[settings.id]: string | number, // Error here
[key: string]: any
}
): object => {
// function logic, doesn't matter
};
return {
test
};
};
I should set an item with required key which I get from the settings object, but I got the error:
A computed property name in a type literal must refer to an expression whose type is a literal type or a 'unique symbol' type.
what I have to do?
UPDATE: is there a way to not use an interface?
UPDATE: the item can be like this: { id: 'someId' }
or { key: 'someKey' }
UPDATE: typescript's version is 4.0.3
item
should look? – yi fan song{ id: 'some-id' ...other }
or{ key: 'some-key' ...other }
, that's means that object can have keyid
orkey
(id
===key
) – meineitem
parameter actually looks like this:{ string: any, ...rest }
that first property name beingproperties.settings.id
? – yi fan song