What does this declaration mean?
_YearlyApyStats({ vaultId }: { vaultId: VaultEntity['id'] }) {
CodePudding user response:
It is a function definition with one parameter.
The parameter is of type { vaultId: VaultEntity['id'] }
, i.e. an object with one property called vaultId
and the type of this property is VaultEntity['id']
, which just means: use the type of the property id
from the VaultEntity
type.
for example, if we have
interface VaultEntity {
id: string;
}
const foo: VaultEntity['id];
then the type of foo
is string
The part { vaultId }
just uses the spread feature to get the vaultId
property from the passed parameter.
i.e. it is the same as:
function _YearlyApyStats(param: { vaultId: VaultEntity['id'] }) {
const vaultId = param.vaultId;
}