# any 타입

## 설명 <a href="#desc" id="desc"></a>

동적 형 지정 언어인 JavaScript는 선언된 변수에 어떤 값이든 재 할당이 가능합니다. 반면 **TypeScript는 명시적으로 데이터 유형을 설정해 사용하는 정적 형 지정 언어로 타입을 지정해 사용하는 것이 권장**됩니다.

하지만 애플리케이션 개발 시 어떤 타입을 할당해야 할지 알지 못하는 경우(외부 라이브러리나 동적 콘텐츠를 사용할 경우)가 있을 수 있습니다. 이런 경우 어떤 타입도 할당 가능하도록 `any`를 설정할 수 있습니다. JavaScript는 기본적으로 변수에 `any`가 할당된 것과 같습니다. (자동으로 형 변환이 이루어집니다)

```typescript
// 명시적으로 any 타입 지정
let product_id:any = 124981;

// any 유형이 설정되었으므로 어떤 유형도 값으로 할당 가능
product_id = 'p9023412';
```

다음과 같이 변수 선언과 초기화 과정에서 값을 할당하지 않으면, 암시적으로 `any` 타입이 지정됩니다.

```typescript
// 암시적으로 any 타입 지정
let product_id;

product_id = 124981;
product_id = 'p9023412';
```

## 실습 <a href="#practice" id="practice"></a>

학습한 내용을 아래 에디터에 직접 입력해 확인해봅니다.

{% embed url="<https://stackblitz.com/edit/ts-any?embed=1&file=index.ts&hideExplorer=1&hideNavigation=1&view=editor>" %}

## 참고 <a href="#reference" id="reference"></a>

{% embed url="<https://www.typescriptlang.org/docs/handbook/basic-types.html#any>" %}
TypeScript - Any 데이터 타입
{% endembed %}


---

# 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://yamoo9.gitbook.io/typescript/types/any.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.
