From e10c6d95f7de8f60a588ac6ad52920396b7ff89f Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Thu, 3 Oct 2019 18:23:52 +0200 Subject: [PATCH] added classes & some fixes --- index.html | 63 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/index.html b/index.html index 1f7ca29..96c2960 100755 --- a/index.html +++ b/index.html @@ -68,9 +68,9 @@

Typescript


-								let a = 'a string' https:// a is a string now
-								a = 5 https:// ❌
-								a = [1, 'two', {three: true}] https:// ❌
+								let a = 'a string' // a is a string now
+								a = 5 // ❌
+								a = [1, 'two', {three: true}] // ❌
 							
@@ -113,7 +113,7 @@ - Autocompletition, "Smart" IDEs, etc. -
+
@@ -190,17 +190,29 @@

Types


 						type StrinOrNumber = string | number
+					
+

 						type StringOrNumberOrBoolean = StringOrNumber | boolean
 					

Modifiers


-						const a: string
-						const b?: string
-						const c!: string
+						const a?: string // string | undefined
 
-						constructor(field?: text)
+						const obj = {
+							a: string,
+							b?: number,
+						}
+
+						funntion log(msg?: string) {}
+					
+

+						class {
+							b!: string
+						}
+
+						obj!.one!.two!.three
 					
@@ -229,7 +241,7 @@ } const pizza: Pizza = { - slices: -1, https:// ❌ + slices: -1, // ❌ round: true, name: 'Margherita' } @@ -302,6 +314,23 @@ }
+
+

Classes

+

+						class User {
+							private id: string
+							public readonly username: string
+							friends: User[] = []
+
+							constructor() {
+								this.id = 'abc'
+								this.username = 'John Doe'
+							}
+
+							private doSomeStuff() {}
+						}
+					
+

Generics


@@ -338,9 +367,9 @@
 							b: string;
 						};
 						
-						const x: Props = { a: 5 }; https:// Error: property 'b' missing
+						const x: Props = { a: 5 }; // Error: property 'b' missing
 						
-						const y: Partial<Props> = { a: 5 }; https:// OK
+						const y: Partial<Props> = { a: 5 }; // OK
 					

 						interface Props {
@@ -348,9 +377,9 @@
 							b?: string;
 						};
 						
-						const x: Props = { a: 5 }; https:// OK
+						const x: Props = { a: 5 }; // OK
 						
-						const y: Required<Props> = { a: 5 }; https:// Error: property 'b' missing
+						const y: Required<Props> = { a: 5 }; // Error: property 'b' missing
 					
@@ -364,7 +393,7 @@ title: 'Delete inactive users', }; - todo.title = 'Hello'; https:// Error: cannot reassign a readonly property + todo.title = 'Hello'; // Error: cannot reassign a readonly property
@@ -429,7 +458,7 @@

 						class Auto {
-							wheels: number
+							wheels!: number
 						
 							constructor(init: typeof Auto) {
 								Object.assign(this, init)
@@ -443,7 +472,7 @@
 						class Auto {
 							wheels?: number
 							doors?: number
-							https:// ...
+							// ...
 						
 							constructor(init: Partial<Auto>) {
 								Object.assign(this, init)
@@ -467,7 +496,7 @@
 						class Auto {
 							wheels!: number
 							doors?: number
-							https:// ...
+							// ...
 						
 							constructor(init: RequireSome<Auto, 'wheels'>) {
 								Object.assign(this, init)