@@ -210,6 +210,19 @@ const username: UserName = {
210
210
name : 'Justin' ,
211
211
}
212
212
213
+ // Access Modifiers - this is a way to make properties of an object private or public
214
+ // public - this is the default
215
+ // private - this is only accessible within the class
216
+ // protected - this is only accessible within the class and any subclasses
217
+ // readonly - this is a property that can only be read, not changed
218
+
219
+ // Type Aliases - this is a way to create a new type
220
+ type ID = string
221
+ type PopularTag = string
222
+ type MaybePopularTag = PopularTag | null
223
+ let popularTags : PopularTag [ ] = [ 'dragon' , 'coffee' ]
224
+ let dragonsTag : MaybePopularTag = 'dragon'
225
+
213
226
// Type Assertion - this is a way to tell the compiler that you know better than it does what the type of a variable is
214
227
let cid : any = 1
215
228
// let customerId = <number>cid // this is the old way
@@ -254,9 +267,29 @@ const user1: UserInterface = {
254
267
id : 1 ,
255
268
name : 'Justin' ,
256
269
}
257
-
258
270
// user1.id = 5 // this will not work because id is read only
259
271
272
+ // Interfaces with classes - this is a way to define a type for a class that can be reused in multiple places
273
+ interface TakePhoto {
274
+ cameraMode : string
275
+ filter : string
276
+ burst : number
277
+ }
278
+ // this is a class that implements the TakePhoto interface
279
+ class Instagram implements TakePhoto {
280
+ cameraMode = 'auto'
281
+ filter = 'normal'
282
+ burst = 3
283
+ }
284
+ // this is a class that implements the TakePhoto interface using a constructor
285
+ class YouTube implements TakePhoto {
286
+ constructor (
287
+ public cameraMode : string ,
288
+ public filter : string ,
289
+ public burst : number ,
290
+ ) { }
291
+ }
292
+
260
293
// Interfaces with functions - this is a way to define a type for a function that can be reused in multiple places
261
294
interface MathFunc {
262
295
( x : number , y : number ) : number
@@ -265,6 +298,13 @@ interface MathFunc {
265
298
const add : MathFunc = ( x : number , y : number ) : number => x + y
266
299
const subtract : MathFunc = ( x : number , y : number ) : number => x - y
267
300
301
+ // Abstract Classes - this is a way to define a type for a class that can be reused in multiple places
302
+ abstract class TakePhoto {
303
+ constructor ( public cameraMode : string , public filter : string ) { }
304
+ }
305
+ // this is a class that extends the TakePhoto abstract class
306
+ class TikTok extends TakePhoto { }
307
+
268
308
// Union - this is a variable that can be multiple types but you can only assign one type
269
309
let pid : string | number = 2
270
310
@@ -326,13 +366,13 @@ class Employee extends Person {
326
366
327
367
const emp = new Employee ( 3 , 'Jupiter' , 25 , 'CEO' ) // this is an instance of the class
328
368
329
- // console.log(justin) // this will work because id and name are public
330
- // console.log(john) // this will work because id and name are public
331
- // console.log(justin.id) // this will work because id is public
332
- // console.log(justin.name) // this will work because name is public
369
+ console . log ( justin ) // this will work because id and name are public
370
+ console . log ( john ) // this will work because id and name are public
371
+ console . log ( justin . id ) // this will work because id is public
372
+ console . log ( justin . name ) // this will work because name is public
333
373
// console.log(justin.age) // this will not work because age is private
334
374
console . log ( justin . register ( ) ) // this will work because register is public
335
- // console.log(employee)
375
+ console . log ( employee )
336
376
console . log ( emp . name ) // this will work because name is public
337
377
338
378
// Generics - this is a way to make a function reusable for multiple types of data (this is a function that takes a string and returns a string)
0 commit comments