diff --git a/docs/language/interfaces.mdx b/docs/language/interfaces.mdx index 031906d9ac..09e2ab4f38 100644 --- a/docs/language/interfaces.mdx +++ b/docs/language/interfaces.mdx @@ -512,3 +512,39 @@ numbers.getCount() // is 0 Interfaces cannot provide default initializers or default destructors. Only one conformance may provide a default function. + +## Nested Type Requirements + + + +🚧 Status: Currently only contracts and contract interfaces support nested type requirements. + + + +Interfaces can require implementing types to provide concrete nested types. +For example, a resource interface may require an implementing type to provide a resource type. + +```cadence +// Declare a resource interface named `FungibleToken`. +// +// Require implementing types to provide a resource type named `Vault` +// which must have a field named `balance`. +// +resource interface FungibleToken { + pub resource Vault { + pub balance: Int + } +} +// Declare a resource named `ExampleToken` that implements the `FungibleToken` interface. +// +// The nested type `Vault` must be provided to conform to the interface. +// +resource ExampleToken: FungibleToken { + pub resource Vault { + pub var balance: Int + init(balance: Int) { + self.balance = balance + } + } +} +```