# Inheritance

Inheritance is supported **for properties** when both the base and the extended class is marked with the `@Service()` decorator. Classes which extend a class with decorated properties will receive the initialized class instances on those properties upon creation.

```ts
import 'reflect-metadata';
import { Container, Token, Inject, Service } from 'typedi';

@Service()
class InjectedClass {
  name: string = 'InjectedClass';
}

@Service()
class BaseClass {
  name: string = 'BaseClass';

  @Inject()
  injectedClass: InjectedClass;
}

@Service()
class ExtendedClass extends BaseClass {
  name: string = 'ExtendedClass';
}

const instance = Container.get(ExtendedClass);
// instance has the `name` property with "ExtendedClass" value (overwritten the base class)
// and the `injectedClass` property with the instance of the `InjectedClass` class

console.log(instance.injectedClass.name);
// logs "InjectedClass"
console.log(instance.name);
// logs "ExtendedClass"
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.typestack.community/typedi/develop/02-basic-usage-guide/07-inheritance.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
