# keyof, typeof

### keyof

**keyof**, oluşturduğumuz tip objelerinde ki keyler ile yeni tipler oluşturmamıza olanak sağlar. Örneğin aşağıdaki gibi [interface](https://afatihyavasi.gitbook.io/typescript-notlari/handbook/interfaces) ile tip tanımlaması yapmış olalım.

```typescript
interface Person {
    name: string
    age: number
    location: string
}
```

Ardından **keyof** ile yeni bir tip oluşturalım.

```typescript
type SomeNewType = keyof Person
```

Oluşturduğumuz tip karşılığı aşağıdaki gibidir.

```typescript
type SomeNewType: "name" | "age" | "location"
```

### typeof

Oluşturduğumuz objelerin value tiplerini elde etmemizi sağlar. Örneğin aşağıdaki gibi obje oluşturalım.

```typescript
const bmw = { name: "BMW", power: "1000hp" }
```

Ardından **typeof bmw** ile yeni bir tip ataması yapalım.

```typescript
type Car = typeof bmw;
```

Yukarıda ki **Car** tip objesinin karşılığı aşağıdaki gibidir.

```typescript
type Car = {
    name: string;
    power: string;
}
```

{% hint style="success" %}
**keyof** ve **typeof** u birlikte kullanabiliriz. Örneğin yukarıdaki örneğimizde ki gibi **bmw** objemizi oluşturalım.

```typescript
const bmw = { name: "BMW", power: "1000hp" }
```

Ardından **keyof** ve **typeof** u birlikte kullanarak yeni bir tip objesi oluşturalım.

```typescript
type CarLiteralType = keyof typeof bmw;
```

oluşturduğumuz tip objesinin karşılığı aşağıdaki gibidir.

```typescript
type CarLiteralType = "name" | "power";
```

�
{% endhint %}

�


---

# 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://afatihyavasi.gitbook.io/typescript-notlari/handbook/keyof.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.
