문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판이전 판다음 판 | 이전 판 | ||
| typescript:namespace [2019/07/30 08:12] – [Multi-file namespaces] taekgu | typescript:namespace [2025/04/15 10:05] (현재) – 바깥 편집 127.0.0.1 | ||
|---|---|---|---|
| 줄 185: | 줄 185: | ||
| ===== Aliases ===== | ===== Aliases ===== | ||
| + | 네임스페이스 작업을 단순화 할 수 있는 또 다른 방법은 '' | ||
| + | <code javascript> | ||
| + | namespace Shapes { | ||
| + | export namespace Polygons { | ||
| + | export class Triangle { } | ||
| + | export class Square { } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | import polygons = Shapes.Polygons; | ||
| + | let sq = new polygons.Square(); | ||
| + | </ | ||
| + | |||
| + | '' | ||
| + | |||
| + | ===== Working with Other JavaScript Libraries ===== | ||
| + | TypeScript로 작성되지 않은 라이브러리의 모양을 설명하려면 라이브러리가 노출하는 API를 선언해야합니다. 대부분의 JavaScript 라이브러리는 몇 개의 최상위 수준 객체 만 노출하므로 네임 스페이스는 객체를 표현할 수있는 좋은 방법입니다. | ||
| + | |||
| + | 구현을 " | ||
| + | |||
| + | ==== Ambient Namespaces ==== | ||
| + | 인기있는 라이브러리 D3은 '' | ||
| + | |||
| + | <code javascript D3.d.ts (simplified excerpt)> | ||
| + | declare namespace D3 { | ||
| + | export interface Selectors { | ||
| + | select: { | ||
| + | (selector: string): Selection; | ||
| + | (element: EventTarget): | ||
| + | }; | ||
| + | } | ||
| + | |||
| + | export interface Event { | ||
| + | x: number; | ||
| + | y: number; | ||
| + | } | ||
| + | |||
| + | export interface Base extends Selectors { | ||
| + | event: Event; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | declare var d3: D3.Base; | ||
| + | </ | ||