You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -163,7 +163,7 @@ Even though `Employee` also has a `private` member called `name`, it's not the a
163
163
164
164
The `protected` modifier acts much like the `private` modifier with the exception that members declared `protected` can also be accessed by instances of deriving classes. For example,
165
165
166
-
```TypeScript
166
+
```ts
167
167
classPerson {
168
168
protected name:string;
169
169
constructor(name:string) { this.name=name; }
@@ -195,7 +195,7 @@ In our last example, we had to declare a private member `name` and a constructor
195
195
This turns out to be a very common practice. *Parameter properties* let you create and initialize a member in one place.
196
196
Here's a further revision of the previous `Animal` class using a parameter property:
197
197
198
-
```TypeScript
198
+
```ts
199
199
classAnimal {
200
200
constructor(privatename:string) { }
201
201
move(distanceInMeters:number) {
@@ -218,7 +218,7 @@ This gives you a way of having finer-grained control over how a member is access
218
218
Let's convert a simple class to use `get` and `set`.
219
219
First, let's start with an example without getters and setters.
220
220
221
-
```TypeScript
221
+
```ts
222
222
classEmployee {
223
223
fullName:string;
224
224
}
@@ -236,7 +236,7 @@ In this version, we check to make sure the user has a secret passcode available
236
236
We do this by replacing the direct access to `fullName` with a `set` that will check the passcode.
237
237
We add a corresponding `get` to allow the previous example to continue to work seamlessly.
238
238
239
-
```TypeScript
239
+
```ts
240
240
var passcode ="secret passcode";
241
241
242
242
classEmployee {
@@ -275,7 +275,7 @@ In this example, we use `static` on the origin, as it's a general value for all
275
275
Each instance accesses this value through prepending the name of the class.
276
276
Similarly to prepending `this.` in front of instance accesses, here we prepend `Grid.` in front of static accesses.
Copy file name to clipboardExpand all lines: pages/Declaration Merging.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ Understanding what is created with each declaration will help you understand wha
35
35
The simplest, and perhaps most common, type of declaration merging is interface merging.
36
36
At the most basic level, the merge mechanically joins the members of both declarations into a single interface with the same name.
37
37
38
-
```TypeScript
38
+
```ts
39
39
interfaceBox {
40
40
height:number;
41
41
width:number;
@@ -56,7 +56,7 @@ Of note, too, is that in the case of interface `A` merging with later interface
56
56
57
57
That is, in the example:
58
58
59
-
```TypeScript
59
+
```ts
60
60
interfaceDocument {
61
61
createElement(tagName:any):Element;
62
62
}
@@ -73,7 +73,7 @@ interface Document {
73
73
The two interfaces will merge to create a single declaration.
74
74
Notice that the elements of each group maintains the same order, just the groups themselves are merged with later overload sets coming first:
75
75
76
-
```TypeScript
76
+
```ts
77
77
interfaceDocument {
78
78
createElement(tagName:"div"):HTMLDivElement;
79
79
createElement(tagName:"span"):HTMLSpanElement;
@@ -95,7 +95,7 @@ To merge the value, at each declaration site, if a namespace already exists with
95
95
96
96
The declaration merge of `Animals` in this example:
97
97
98
-
```TypeScript
98
+
```ts
99
99
namespaceAnimals {
100
100
exportclassZebra { }
101
101
}
@@ -108,7 +108,7 @@ namespace Animals {
108
108
109
109
is equivalent to:
110
110
111
-
```TypeScript
111
+
```ts
112
112
namespaceAnimals {
113
113
exportinterfaceLegged { numberOfLegs:number; }
114
114
@@ -122,7 +122,7 @@ Non-exported members are only visible in the original (un-merged) namespace. Thi
122
122
123
123
We can see this more clearly in this example:
124
124
125
-
```TypeScript
125
+
```ts
126
126
namespaceAnimal {
127
127
var haveMuscles =true;
128
128
@@ -150,7 +150,7 @@ TypeScript uses this capability to model some of patterns in JavaScript as well
150
150
The first namespace merge we'll cover is merging a namespace with a class.
151
151
This gives the user a way of describing inner classes.
152
152
153
-
```TypeScript
153
+
```ts
154
154
classAlbum {
155
155
label:Album.AlbumLabel;
156
156
}
@@ -166,7 +166,7 @@ You can also use namespaces to add more static members to an existing class.
166
166
In addition to the pattern of inner classes, you may also be familiar with JavaScript practice of creating a function and then extending the function further by adding properties onto the function.
167
167
TypeScript uses declaration merging to build up definitions like this in a type-safe way.
0 commit comments