Skip to content

Commit 2c8bba7

Browse files
authored
intersection type: first commit (#170)
1 parent fc4defa commit 2c8bba7

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

Diff for: โ€Žpages/unions-and-intersections.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,15 @@ function networkStatus(state: NetworkState): string {
223223
}
224224
```
225225

226-
# Intersection Types
226+
# ๊ต์ฐจ ํƒ€์ž… (Intersection Types)
227227

228-
Intersection types are closely related to union types, but they are used very differently.
229-
An intersection type combines multiple types into one.
230-
This allows you to add together existing types to get a single type that has all the features you need.
231-
For example, `Person & Serializable & Loggable` is a type which is all of `Person` _and_ `Serializable` _and_ `Loggable`.
232-
That means an object of this type will have all members of all three types.
228+
๊ต์ฐจ ํƒ€์ž…์€ ์œ ๋‹ˆ์–ธ ํƒ€์ž…๊ณผ ๋ฐ€์ ‘ํ•œ ๊ด€๋ จ์ด ์žˆ์ง€๋งŒ, ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์€ ๋งค์šฐ ๋‹ค๋ฆ…๋‹ˆ๋‹ค.
229+
๊ต์ฐจ ํƒ€์ž…์€ ์—ฌ๋Ÿฌ ํƒ€์ž…์„ ํ•˜๋‚˜๋กœ ๊ฒฐํ•ฉํ•ฉ๋‹ˆ๋‹ค.
230+
๊ธฐ์กด ํƒ€์ž…์„ ํ•ฉ์ณ ํ•„์š”ํ•œ ๊ธฐ๋Šฅ์„ ๋ชจ๋‘ ๊ฐ€์ง„ ๋‹จ์ผ ํƒ€์ž…์„ ์–ป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
231+
์˜ˆ๋ฅผ ๋“ค์–ด, `Person & Serializable & Loggable`์€ `Person` _๊ณผ_ `Serializable` _๊ทธ๋ฆฌ๊ณ _ `Loggable`์ž…๋‹ˆ๋‹ค.
232+
์ฆ‰, ์ด ํƒ€์ž…์˜ ๊ฐ์ฒด๋Š” ์„ธ ๊ฐ€์ง€ ํƒ€์ž…์˜ ๋ชจ๋“  ๋ฉค๋ฒ„๋ฅผ ๊ฐ–๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
233233

234-
For example, if you had networking requests with consistent error handling then you could separate out the error handling into it's own type which is merged with types which correspond to a single response type.
234+
์˜ˆ๋ฅผ ๋“ค์–ด, ์ผ๊ด€๋œ ์—๋Ÿฌ๋ฅผ ๋‹ค๋ฃจ๋Š” ์—ฌ๋Ÿฌ ๋„คํŠธ์›Œํฌ ์š”์ฒญ์ด ์žˆ๋‹ค๋ฉด ํ•ด๋‹น ์—๋Ÿฌ ํ•ธ๋“ค๋ง์„ ๋ถ„๋ฆฌํ•˜์—ฌ ํ•˜๋‚˜์˜ ์‘๋‹ต ํƒ€์ž…์— ๋Œ€์‘ํ•˜๋Š” ๊ฒฐํ•ฉ๋œ ์ž์ฒด ํƒ€์ž…์œผ๋กœ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
235235

236236
```ts
237237
interface ErrorHandling {
@@ -247,8 +247,8 @@ interface ArtistsData {
247247
artists: { name: string }[];
248248
}
249249

250-
// These interfaces are composed to have
251-
// consistent error handling, and their own data.
250+
// ์ด ์ธํ„ฐํŽ˜์ด์Šค๋“ค์€
251+
// ํ•˜๋‚˜์˜ ์—๋Ÿฌ ํ•ธ๋“ค๋ง๊ณผ ์ž์ฒด ๋ฐ์ดํ„ฐ๋กœ ๊ตฌ์„ฑ๋ฉ๋‹ˆ๋‹ค.
252252

253253
type ArtworksResponse = ArtworksData & ErrorHandling;
254254
type ArtistsResponse = ArtistsData & ErrorHandling;
@@ -263,9 +263,9 @@ const handleArtistsResponse = (response: ArtistsResponse) => {
263263
};
264264
```
265265

266-
## Mixins via Intersections
266+
## ๊ต์ฐจ๋ฅผ ํ†ตํ•œ ๋ฏน์Šค์ธ (Mixins via Intersections)
267267

268-
Intersections are used to implement the [mixin pattern](/docs/handbook/mixins.html):
268+
๊ต์ฐจ๋Š” [๋ฏน์Šค์ธ ํŒจํ„ด](/docs/handbook/mixins.html)์„ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.
269269

270270
```ts
271271
class Person {
@@ -282,7 +282,7 @@ class ConsoleLogger implements Loggable {
282282
}
283283
}
284284

285-
// Takes two objects and merges them together
285+
// ๋‘ ๊ฐ์ฒด๋ฅผ ๋ฐ›์•„ ํ•˜๋‚˜๋กœ ํ•ฉ์นฉ๋‹ˆ๋‹ค.
286286
function extend<First extends {}, Second extends {}>(
287287
first: First,
288288
second: Second

0 commit comments

Comments
ย (0)