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
Copy file name to clipboardExpand all lines: README.md
+20-10Lines changed: 20 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -175,11 +175,16 @@ Yes, the code is valid. A class declaration creates two things: a type represent
175
175
<b><a href="#">↥ back to top</a></b>
176
176
</div>
177
177
178
-
## Q. Explain how and why we could use property decorators in TS?
178
+
## Q. Explain decorators in TS?
179
179
180
-
Decorators can be used to modify the behavior of a class or become even more powerful when integrated into a framework. For instance, if your framework has methods with restricted access requirements (just for admin), it would be easy to write an @admin method decorator to deny access to non-administrative users, or an @owner decorator to only allow the owner of an object the ability to modify it.
180
+
Decorators can be used to modify the behavior of a class or become even more powerful when integrated into a framework. For instance, if your framework has methods with restricted access requirements (just for admin), it would be easy to write an `@admin` method decorator to deny access to non-administrative users, or an `@owner` decorator to only allow the owner of an object the ability to modify it.
181
+
182
+
**Example:**
181
183
182
184
```ts
185
+
/**
186
+
* Decorators
187
+
*/
183
188
classEmployee {
184
189
get() { }
185
190
post() { }
@@ -196,9 +201,21 @@ class Employee {
196
201
<b><a href="#">↥ back to top</a></b>
197
202
</div>
198
203
199
-
## Q. What is the difference between "interface vs type" statements?
204
+
## Q. What is the difference between interface and type statements?
205
+
206
+
|Interface |Type |
207
+
|----------|-------|
208
+
|An interface declaration always introduces a named object type. |A type alias declaration can introduce a name for any kind of type, including primitive, union, and intersection types.|
209
+
|An interface can be named in an extends or implements clause. |Type alias for an object type literal cannot be named in an |extends or implements clause.|
210
+
|Interfaces create a new name that is used everywhere. |Type aliases don\'t create a new name.|
211
+
|An interface can have multiple merged declarations. |Type alias for an object type literal cannot have multiple merged declarations.|
212
+
213
+
**Example:**
200
214
201
215
```ts
216
+
/**
217
+
* Interface vs Type
218
+
*/
202
219
interfaceX {
203
220
a:number
204
221
b:string
@@ -210,13 +227,6 @@ type X = {
210
227
};
211
228
```
212
229
213
-
|interface |type |
214
-
|----------|-------|
215
-
|An interface declaration always introduces a named object type. | A type alias declaration can introduce a name for any kind of type, including primitive, union, and intersection types.|
216
-
|An interface can be named in an extends or implements clause. |Type alias for an object type literal cannot be named in an |extends or implements clause.|
217
-
|Interfaces create a new name that is used everywhere. |Type aliases don't create a new name.|
218
-
|An interface can have multiple merged declarations. |Type alias for an object type literal cannot have multiple merged declarations.|
0 commit comments