Type 선언을 위한 방식 (interface VS type) #4
Replies: 5 comments
-
|
근데 찾아보니 하단은 예시 코드입니다! // 원시 타입 선언
type Name = string; // primitive
type Age = number;
type Person = [string, number, boolean]; // tuple
type NumberString = string | number; // union
//computed value
type Subjects = 'Math' | 'Science' | 'Sociology';
type Grades = {
[key in Subjects]: string;
} |
Beta Was this translation helpful? Give feedback.
-
|
저는 찾아본 결과,
이런 상황을 고려했을 때 그런데... 정말 간단한 타입을 지정하는 상황이 발생했을 때를 고려하여, 그럴 경우에만 |
Beta Was this translation helpful? Give feedback.
-
|
저는 팀프로젝트이기 때문에 type 별칭을 사용하는 것이 적합하다고 생각합니다. 왜냐하면 interface는 확장이 가능하기 때문입니다.
|
Beta Was this translation helpful? Give feedback.
-
|
그냥 여담이지만 |
Beta Was this translation helpful? Give feedback.
-
|
TypeScript를 사용하는 주요 이유 중 하나는 타입
이러한 문제를 방지하려면, 따라서 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
TypeScript에선 변수에 대한 타입을 설정해서 사용하고, 서버로부터 데이터를 받아오는 것도
미리 해당 데이터에 대한 구조를 선언해야합니다!
이때 2가지 방식으로 타입을 선언할 수 있는데,
interface와type이 있습니다.저는 일반적으로 확장시킬 수 있고, 필요에 따라 조작할 수 있는
interface로 타입을 선언하는 것을 추천합니다!이에 대해서 여러 의견 주시면 감사하겠습니다!
Beta Was this translation helpful? Give feedback.
All reactions