# type과 interface

https://velog.io/@wlwl99/TypeScript-type%EA%B3%BC-interface%EC%9D%98-%EC%B0%A8%EC%9D%B4 

### interface

- extends 키워드를 통해 확장할 수 있다.

- 같은 이름의 interface를 정의하면 자동으로 확장되는 **선언적 확장**이 가능하다.

- 객체 (Object) 타입을 설정할 때 사용할 수 있으며 원시 자료형에는 사용할 수 없다.

- computed value 사용이 불가하다.

### type

- `&` 키워드를 통해 확장할 수 있다.

- 선언적 확장이 불가하다.

- 객체 타입을 정의할 때도 사용할 수 있지만, 객체 타입을 정의할 때는 `interface` 를 사용하는 것이 되도록 편할 것이며, 단순한 원시 값 (Primitive 한) 이나 튜플, 유니언 타입( `|` ) 을 선언할 때 `type` 을 사용하는 것이 좋다.

- computed value 사용이 가능하다.

### computed value

```
type Subjects = 'math' | 'science' | 'sociology';

interface Grades {
  [key in Subjects]: string;
}
```

For the site tree, see the [root Markdown](https://slashpage.com/timmy.md).
