source

TypeScript 인터페이스 구성 방법

nicesource 2023. 2. 10. 22:03
반응형

TypeScript 인터페이스 구성 방법

인터페이스 정의를 타이프 스크립트로 정리하는 권장 방법을 알고 싶습니다.내 프로젝트에서 나는 많은 다른 수업을 듣는다.각 클래스에는 컨피규레이션인터페이스를 설정할 수 있습니다.현재 이 모든 인터페이스 정의를 1개의 파일로 수집했습니다.Interfaces.ts다양한 장소에서 파일을 참조합니다.

더 좋은 방법이 있을까요?

예: https://github.com/blendsdk/blendjs/blob/devel/blend/src/common/Interfaces.ts

세계적인

TypeScript 팀은 다음과 같은 파일을 사용합니다.types.ts: https://github.com/Microsoft/TypeScript/blob/master/src/compiler/types.ts

프로젝트(https://github.com/alm-tools/alm/blob/master/src/common/types.ts 등)에서도 같은 작업을 하고 있습니다.

대안

재사용률이 높은 부분이 속하는 은 괜찮습니다.types단, 특정 유형으로 오염시키지 마십시오.특정 유형은 참조에 더 가까울 수 있습니다. 예를 들어 반응 스타일 소품이 반응 구성요소 옆에 속합니다(같은 파일에 속함).

리액트 컴포넌트 프로펠러 타입 / 리액트 컴포넌트

앱의 구성은 다음과 같습니다.

|-- app
    |-- components
    |-- directives
    |-- services
    |-- interfaces
        |-- <feature/component name>
            |-- <interface name>.interface.ts

내 프로젝트는 이렇게 구성되어 있다.

src/
└── ts
    ├── enums
    │   ├── app_enums.ts
    │   └── db_enums.ts
    ├── interfaces
    │   ├── app_interfaces.ts
    │   ├── db_interfaces.ts
    │   └── global_interfaces.ts
    └── types
        └── app_types.ts

언급URL : https://stackoverflow.com/questions/36633033/how-to-organize-typescript-interfaces

반응형