From 03bab0e47b38c113e26c064b11cbd171675214a1 Mon Sep 17 00:00:00 2001 From: Thien Do Date: Mon, 21 Nov 2016 02:31:22 +0700 Subject: Use ts for typescript syntax --- typescript.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index 1d712369..204b501a 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -13,7 +13,7 @@ This article will focus only on TypeScript extra syntax, as opposed to [JavaScri To test TypeScript's compiler, head to the [Playground] (http://www.typescriptlang.org/Playground) where you will be able to type code, have auto completion and directly see the emitted JavaScript. -```js +```ts // There are 3 basic types in TypeScript var isDone: boolean = false; var lines: number = 42; -- cgit v1.2.3 From ac99d3f1cba2d49a7b2560fe338f6a14044a6eaa Mon Sep 17 00:00:00 2001 From: Thien Do Date: Mon, 21 Nov 2016 03:41:16 +0700 Subject: [typescript/en-us] Clarify function section in typescript (#2575) * Clarify function section in typescript * one-liner to braceless --- typescript.html.markdown | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index 1d712369..23e0bab4 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -46,10 +46,12 @@ function bigHorribleAlert(): void { var f1 = function(i: number): number { return i * i; } // Return type inferred var f2 = function(i: number) { return i * i; } +// "Fat arrow" syntax var f3 = (i: number): number => { return i * i; } -// Return type inferred +// "Fat arrow" syntax with return type inferred var f4 = (i: number) => { return i * i; } -// Return type inferred, one-liner means no return keyword needed +// "Fat arrow" syntax with return type inferred, braceless means no return +// keyword needed var f5 = (i: number) => i * i; // Interfaces are structural, anything that has the properties is compliant with -- cgit v1.2.3 From 1ac2f69479caef3218e3bf8ab6d88351af9ed3eb Mon Sep 17 00:00:00 2001 From: bezigon Date: Thu, 25 May 2017 18:35:08 +0300 Subject: Update typescript.html.markdown (#2738) https://github.com/adambard/learnxinyminutes-docs/issues/2737 --- typescript.html.markdown | 65 +++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 28 deletions(-) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index d3ca0786..ef37182d 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -15,23 +15,32 @@ To test TypeScript's compiler, head to the [Playground] (http://www.typescriptla ```ts // There are 3 basic types in TypeScript -var isDone: boolean = false; -var lines: number = 42; -var name: string = "Anders"; +let isDone: boolean = false; +let lines: number = 42; +let name: string = "Anders"; + +// But you can omit the type annotation if the variables are derived from explicit literals +let isDone = false; +let lines = 42; +let name = "Anders"; // When it's impossible to know, there is the "Any" type -var notSure: any = 4; +let notSure: any = 4; notSure = "maybe a string instead"; notSure = false; // okay, definitely a boolean +// Use const keyword for constant variables +const numLivesForCat = 9; +numLivesForCat = 1; // Error + // For collections, there are typed arrays and generic arrays -var list: number[] = [1, 2, 3]; +let list: number[] = [1, 2, 3]; // Alternatively, using the generic array type -var list: Array = [1, 2, 3]; +let list: Array = [1, 2, 3]; // For enumerations: -enum Color {Red, Green, Blue}; -var c: Color = Color.Green; +enum Color { Red, Green, Blue }; +let c: Color = Color.Green; // Lastly, "void" is used in the special case of a function returning nothing function bigHorribleAlert(): void { @@ -43,16 +52,16 @@ function bigHorribleAlert(): void { // The following are equivalent, the same signature will be infered by the // compiler, and same JavaScript will be emitted -var f1 = function(i: number): number { return i * i; } +let f1 = function (i: number): number { return i * i; } // Return type inferred -var f2 = function(i: number) { return i * i; } +let f2 = function (i: number) { return i * i; } // "Fat arrow" syntax -var f3 = (i: number): number => { return i * i; } +let f3 = (i: number): number => { return i * i; } // "Fat arrow" syntax with return type inferred -var f4 = (i: number) => { return i * i; } +let f4 = (i: number) => { return i * i; } // "Fat arrow" syntax with return type inferred, braceless means no return // keyword needed -var f5 = (i: number) => i * i; +let f5 = (i: number) => i * i; // Interfaces are structural, anything that has the properties is compliant with // the interface @@ -66,19 +75,19 @@ interface Person { // Object that implements the "Person" interface // Can be treated as a Person since it has the name and move properties -var p: Person = { name: "Bobby", move: () => {} }; +let p: Person = { name: "Bobby", move: () => { } }; // Objects that have the optional property: -var validPerson: Person = { name: "Bobby", age: 42, move: () => {} }; +let validPerson: Person = { name: "Bobby", age: 42, move: () => { } }; // Is not a person because age is not a number -var invalidPerson: Person = { name: "Bobby", age: true }; +let invalidPerson: Person = { name: "Bobby", age: true }; // Interfaces can also describe a function type interface SearchFunc { (source: string, subString: string): boolean; } // Only the parameters' types are important, names are not important. -var mySearch: SearchFunc; -mySearch = function(src: string, sub: string) { +let mySearch: SearchFunc; +mySearch = function (src: string, sub: string) { return src.search(sub) != -1; } @@ -104,8 +113,8 @@ class Point { static origin = new Point(0, 0); } -var p1 = new Point(10 ,20); -var p2 = new Point(25); //y will be 0 +let p1 = new Point(10, 20); +let p2 = new Point(25); //y will be 0 // Inheritance class Point3D extends Point { @@ -115,7 +124,7 @@ class Point3D extends Point { // Overwrite dist() { - var d = super.dist(); + let d = super.dist(); return Math.sqrt(d * d + this.z * this.z); } } @@ -131,12 +140,12 @@ module Geometry { } } -var s1 = new Geometry.Square(5); +let s1 = new Geometry.Square(5); // Local alias for referencing a module import G = Geometry; -var s2 = new G.Square(10); +let s2 = new G.Square(10); // Generics // Classes @@ -152,21 +161,21 @@ interface Pair { } // And functions -var pairToTuple = function(p: Pair) { +let pairToTuple = function (p: Pair) { return new Tuple(p.item1, p.item2); }; -var tuple = pairToTuple({ item1:"hello", item2:"world"}); +let tuple = pairToTuple({ item1: "hello", item2: "world" }); // Including references to a definition file: /// // Template Strings (strings that use backticks) // String Interpolation with Template Strings -var name = 'Tyrone'; -var greeting = `Hi ${name}, how are you?` +let name = 'Tyrone'; +let greeting = `Hi ${name}, how are you?` // Multiline Strings with Template Strings -var multiline = `This is an example +let multiline = `This is an example of a multiline string`; ``` -- cgit v1.2.3 From 985d23a52b76593a120adff5381c2df3a80fe298 Mon Sep 17 00:00:00 2001 From: HairyFotr Date: Wed, 23 Aug 2017 10:14:39 +0200 Subject: Fix a bunch of typos --- typescript.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index ef37182d..44fd791a 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -50,7 +50,7 @@ function bigHorribleAlert(): void { // Functions are first class citizens, support the lambda "fat arrow" syntax and // use type inference -// The following are equivalent, the same signature will be infered by the +// The following are equivalent, the same signature will be inferred by the // compiler, and same JavaScript will be emitted let f1 = function (i: number): number { return i * i; } // Return type inferred -- cgit v1.2.3 From 838efd36532faf52d631bbc798b284bbc7867479 Mon Sep 17 00:00:00 2001 From: Allwin Baby Panikulam Date: Thu, 26 Oct 2017 01:12:10 +0800 Subject: Fix link to javascript docs --- typescript.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index 44fd791a..10f01ebc 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -9,7 +9,7 @@ TypeScript is a language that aims at easing development of large scale applicat TypeScript adds common concepts such as classes, modules, interfaces, generics and (optional) static typing to JavaScript. It is a superset of JavaScript: all JavaScript code is valid TypeScript code so it can be added seamlessly to any project. The TypeScript compiler emits JavaScript. -This article will focus only on TypeScript extra syntax, as opposed to [JavaScript](javascript.html.markdown). +This article will focus only on TypeScript extra syntax, as opposed to [JavaScript](/docs/javascript). To test TypeScript's compiler, head to the [Playground] (http://www.typescriptlang.org/Playground) where you will be able to type code, have auto completion and directly see the emitted JavaScript. -- cgit v1.2.3 From 0d0b536b28d7f3ed8d35cc557142b15d52299526 Mon Sep 17 00:00:00 2001 From: Simon Siegert Date: Thu, 25 Jan 2018 20:56:33 +0100 Subject: Fix naming of constant --- typescript.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index 10f01ebc..acc258b4 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -29,7 +29,7 @@ let notSure: any = 4; notSure = "maybe a string instead"; notSure = false; // okay, definitely a boolean -// Use const keyword for constant variables +// Use const keyword for constants const numLivesForCat = 9; numLivesForCat = 1; // Error -- cgit v1.2.3 From f8ff01a17eff289e6e5e84a129dd29fa9a8bcdff Mon Sep 17 00:00:00 2001 From: Wayne Boka Date: Wed, 3 Oct 2018 16:23:54 -0400 Subject: Add Readonly Examples In references to #2702. Making another commit due to several extra files getting committed. --- typescript.html.markdown | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index acc258b4..db6579e2 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -178,6 +178,37 @@ let greeting = `Hi ${name}, how are you?` let multiline = `This is an example of a multiline string`; +// READONLY: New Feature in TypeScript 3.1 +interface Person { + readonly name: string; + readonly age: number; +} + +var p1: Person = { name: "Tyrone", age: 42 }; +p1.age = 25; // Error, p1.x is read-only + +var p2 = { name: "John", age: 60 }; +var p3: Person = p2; // Ok, read-only alias for p2 +p3.x = 35; // Error, p3.x is read-only +p2.x = 45; // Ok, but also changes p3.x because of aliasing + +class Car { + readonly make: string; + readonly model: string; + readonly year = 2018; + + constructor() { + this.make = "Unknown Make"; // Assignment permitted in constructor + this.model = "Unknown Model"; // Assignment permitted in constructor + } +} + +let numbers: Array = [0, 1, 2, 3, 4]; +let moreNumbers: ReadonlyArray = numbers; +moreNumbers[5] = 5; // Error, elements are read-only +moreNumbers.push(5); // Error, no push method (because it mutates array) +moreNumbers.length = 3; // Error, length is read-only +numbers = moreNumbers; // Error, mutating methods are missing ``` ## Further Reading -- cgit v1.2.3 From 67730b4e0b3100a7a6df925ef28606b71aa30a43 Mon Sep 17 00:00:00 2001 From: Bradley Kemp Date: Fri, 19 Oct 2018 13:55:51 +0100 Subject: Add example of "implements" keyword --- typescript.html.markdown | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index db6579e2..9158f123 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -113,6 +113,13 @@ class Point { static origin = new Point(0, 0); } +// Classes can be explicitly marked as implementing an interface. +// Any missing properties will then cause an error at compile-time. +class PointPerson implements Person { + name: string + move() {} +} + let p1 = new Point(10, 20); let p2 = new Point(25); //y will be 0 -- cgit v1.2.3 From a41c5d77c29c6775e060a1f559584810e1390bd8 Mon Sep 17 00:00:00 2001 From: Kyle Mendes Date: Tue, 30 Oct 2018 12:40:01 -0500 Subject: Updating the line length to 80 --- typescript.html.markdown | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index 9158f123..6feaca45 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -5,13 +5,19 @@ contributors: filename: learntypescript.ts --- -TypeScript is a language that aims at easing development of large scale applications written in JavaScript. -TypeScript adds common concepts such as classes, modules, interfaces, generics and (optional) static typing to JavaScript. -It is a superset of JavaScript: all JavaScript code is valid TypeScript code so it can be added seamlessly to any project. The TypeScript compiler emits JavaScript. +TypeScript is a language that aims at easing development of large scale +applications written in JavaScript. TypeScript adds common concepts such as +classes, modules, interfaces, generics and (optional) static typing to +JavaScript. It is a superset of JavaScript: all JavaScript code is valid +TypeScript code so it can be added seamlessly to any project. The TypeScript +compiler emits JavaScript. -This article will focus only on TypeScript extra syntax, as opposed to [JavaScript](/docs/javascript). +This article will focus only on TypeScript extra syntax, as opposed to +[JavaScript](/docs/javascript). -To test TypeScript's compiler, head to the [Playground] (http://www.typescriptlang.org/Playground) where you will be able to type code, have auto completion and directly see the emitted JavaScript. +To test TypeScript's compiler, head to the +[Playground] (http://www.typescriptlang.org/Playground) where you will be able +to type code, have auto completion and directly see the emitted JavaScript. ```ts // There are 3 basic types in TypeScript @@ -19,7 +25,8 @@ let isDone: boolean = false; let lines: number = 42; let name: string = "Anders"; -// But you can omit the type annotation if the variables are derived from explicit literals +// But you can omit the type annotation if the variables are derived +// from explicit literals let isDone = false; let lines = 42; let name = "Anders"; @@ -114,7 +121,7 @@ class Point { } // Classes can be explicitly marked as implementing an interface. -// Any missing properties will then cause an error at compile-time. +// Any missing properties will then cause an error at compile-time. class PointPerson implements Person { name: string move() {} -- cgit v1.2.3 From 217e32442cfd9550ad53f92ce1470527ed1b89a9 Mon Sep 17 00:00:00 2001 From: Elton Maiyo Date: Sun, 27 Jan 2019 18:06:34 +0300 Subject: Fixes typo --- typescript.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index 6feaca45..ba4a9e71 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -203,8 +203,8 @@ p1.age = 25; // Error, p1.x is read-only var p2 = { name: "John", age: 60 }; var p3: Person = p2; // Ok, read-only alias for p2 -p3.x = 35; // Error, p3.x is read-only -p2.x = 45; // Ok, but also changes p3.x because of aliasing +p3.age = 35; // Error, p3.age is read-only +p2.age = 45; // Ok, but also changes p3.age because of aliasing class Car { readonly make: string; -- cgit v1.2.3 From 145e76d3b318eab8ff78980c57f34e622a1988b2 Mon Sep 17 00:00:00 2001 From: ashraf-patel Date: Mon, 17 Jun 2019 14:52:58 +0530 Subject: Iterators and Generators --- typescript.html.markdown | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index ba4a9e71..9f0f4c6d 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -223,6 +223,25 @@ moreNumbers[5] = 5; // Error, elements are read-only moreNumbers.push(5); // Error, no push method (because it mutates array) moreNumbers.length = 3; // Error, length is read-only numbers = moreNumbers; // Error, mutating methods are missing + +// Iterators and Generators + +// for..of statement +// iterate over the list of values on the object being iterated +let list = [4, 5, 6]; +for (let i of list) { + console.log(i); // "4", "5", "6" +} + +// for..in statement +// iterate over the list of keys on the object being iterated +for (let i in list) { + console.log(i); // "0", "1", "2", +} + + + + ``` ## Further Reading -- cgit v1.2.3 From 1b67ecb30c8c634d7f1688696979798e658ca936 Mon Sep 17 00:00:00 2001 From: ashraf-patel Date: Mon, 17 Jun 2019 14:56:28 +0530 Subject: Add one more example --- typescript.html.markdown | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index 9f0f4c6d..827f202a 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -228,6 +228,11 @@ numbers = moreNumbers; // Error, mutating methods are missing // for..of statement // iterate over the list of values on the object being iterated +let arrayOfAnyType = [1, "string", false]; +for (let val of arrayOfAnyType) { + console.log(val); // 1, "string", false +} + let list = [4, 5, 6]; for (let i of list) { console.log(i); // "4", "5", "6" -- cgit v1.2.3 From ff3dd723599190ccb1b5454f297d116b5c446c70 Mon Sep 17 00:00:00 2001 From: ashraf-patel Date: Tue, 18 Jun 2019 12:21:00 +0530 Subject: PR changes: use const instead of let --- typescript.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index 827f202a..55d8cefe 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -229,18 +229,18 @@ numbers = moreNumbers; // Error, mutating methods are missing // for..of statement // iterate over the list of values on the object being iterated let arrayOfAnyType = [1, "string", false]; -for (let val of arrayOfAnyType) { +for (const val of arrayOfAnyType) { console.log(val); // 1, "string", false } let list = [4, 5, 6]; -for (let i of list) { +for (const i of list) { console.log(i); // "4", "5", "6" } // for..in statement // iterate over the list of keys on the object being iterated -for (let i in list) { +for (const i in list) { console.log(i); // "0", "1", "2", } -- cgit v1.2.3 From 96b65fb40d84ce97b6ca7b814e210a61bca294df Mon Sep 17 00:00:00 2001 From: Piotr Monwid-Olechnowicz Date: Wed, 3 Jul 2019 23:15:10 +0200 Subject: [typescript/en] Add tagged union types They're super useful. https://www.typescriptlang.org/docs/handbook/advanced-types.html#discriminated-unions https://mariusschulz.com/blog/typescript-2-0-tagged-union-types --- typescript.html.markdown | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index 55d8cefe..293a4a35 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -224,6 +224,19 @@ moreNumbers.push(5); // Error, no push method (because it mutates array) moreNumbers.length = 3; // Error, length is read-only numbers = moreNumbers; // Error, mutating methods are missing +// Tagged Union Types for modelling state that can be in one of many shapes +type State = + | { type: "loading" } + | { type: "success", value: number } + | { type: "error", message: string }; + +declare const state: State; +if (state.type === "success") { + console.log(state.value); +} else if (state.type === "error") { + console.error(state.message); +} + // Iterators and Generators // for..of statement -- cgit v1.2.3 From 7fa8cc63c85f331e81a51443d9a81a9e058e8f42 Mon Sep 17 00:00:00 2001 From: Monis Qadri Date: Wed, 31 Jul 2019 13:06:54 +0530 Subject: Update typescript.html.markdown The input list is of int[] [@line236](https://github.com/adambard/learnxinyminutes-docs/blame/master/typescript.html.markdown#L236]) but the output of its shown is in string [@line238](https://github.com/adambard/learnxinyminutes-docs/blame/master/typescript.html.markdown#L238]). same thing happens at [@line244](https://github.com/adambard/learnxinyminutes-docs/blame/master/typescript.html.markdown#L244]) --- typescript.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index 55d8cefe..c27e93a6 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -235,13 +235,13 @@ for (const val of arrayOfAnyType) { let list = [4, 5, 6]; for (const i of list) { - console.log(i); // "4", "5", "6" + console.log(i); // 4, 5, 6 } // for..in statement // iterate over the list of keys on the object being iterated for (const i in list) { - console.log(i); // "0", "1", "2", + console.log(i); // 0, 1, 2 } -- cgit v1.2.3 From 0e437a75db091eb5cb057f1a49bf07db562d1d8f Mon Sep 17 00:00:00 2001 From: davidgtu Date: Fri, 11 Oct 2019 15:53:07 -0400 Subject: add type assertion --- typescript.html.markdown | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index cf2111d5..6c6da2c4 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -257,8 +257,24 @@ for (const i in list) { console.log(i); // 0, 1, 2 } +// Type Assertion +let foo = {} // Creating foo as an empty object +foo.bar = 123 // Error: property 'bar' does not exist on `{}` +foo.baz = 'hello world' // Error: property 'baz' does not exist on `{}` +// Because the inferred type of foo is `{}` (an object with 0 properties), you +// are not allowed to add bar and baz to it. However with type assertion, +// the following will pass: + +interface Foo { + bar: number; + baz: string; +} + +let foo = {} as Foo; // Type assertion here +foo.bar = 123; +foo.baz = 'hello world' ``` -- cgit v1.2.3 From fb48be47d6cac609cf9d29caae5d4e73df3e214a Mon Sep 17 00:00:00 2001 From: Ross Mackay Date: Tue, 22 Oct 2019 13:16:52 +0100 Subject: Fix outdated comment in en/th-th typescript docs --- typescript.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index cf2111d5..6f238d5b 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -199,7 +199,7 @@ interface Person { } var p1: Person = { name: "Tyrone", age: 42 }; -p1.age = 25; // Error, p1.x is read-only +p1.age = 25; // Error, p1.age is read-only var p2 = { name: "John", age: 60 }; var p3: Person = p2; // Ok, read-only alias for p2 -- cgit v1.2.3 From 5a7d3e898b11fb09cfa448e924ef09970b071a51 Mon Sep 17 00:00:00 2001 From: Kyle Mendes Date: Thu, 31 Oct 2019 18:42:00 -0500 Subject: Fix playground link --- typescript.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index 6f238d5b..a4f1423f 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -16,7 +16,7 @@ This article will focus only on TypeScript extra syntax, as opposed to [JavaScript](/docs/javascript). To test TypeScript's compiler, head to the -[Playground] (http://www.typescriptlang.org/Playground) where you will be able +[Playground](http://www.typescriptlang.org/Playground) where you will be able to type code, have auto completion and directly see the emitted JavaScript. ```ts -- cgit v1.2.3 From d430cd82b6c00d0df4aa637697caaaf490cda191 Mon Sep 17 00:00:00 2001 From: Kyle Mendes Date: Mon, 4 Nov 2019 14:11:16 -0600 Subject: Updating the TS playground link --- typescript.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index a4f1423f..00f0cbc5 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -16,7 +16,7 @@ This article will focus only on TypeScript extra syntax, as opposed to [JavaScript](/docs/javascript). To test TypeScript's compiler, head to the -[Playground](http://www.typescriptlang.org/Playground) where you will be able +[Playground](https://www.typescriptlang.org/play) where you will be able to type code, have auto completion and directly see the emitted JavaScript. ```ts -- cgit v1.2.3 From 5a57d01d05d1b53a8e2eb267ecc56ddbd75a6d46 Mon Sep 17 00:00:00 2001 From: lemusthelroy Date: Fri, 13 Dec 2019 07:43:47 +0000 Subject: Update typescript.html.markdown This will overcome TSError:2362 : "The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type" --- typescript.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index 00f0cbc5..eeda0b7b 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -139,7 +139,7 @@ class Point3D extends Point { // Overwrite dist() { let d = super.dist(); - return Math.sqrt(d * d + this.z * this.z); + return Math.sqrt(d() * d() + this.z * this.z); } } -- cgit v1.2.3 From d0e82c10cd98e82100f3efac298d24d4d58ded9e Mon Sep 17 00:00:00 2001 From: Rett Berg Date: Sat, 21 Mar 2020 11:20:23 -0600 Subject: add type to Point.dist and fix error --- typescript.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'typescript.html.markdown') diff --git a/typescript.html.markdown b/typescript.html.markdown index 640be0cd..f7a41ce1 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -114,7 +114,7 @@ class Point { } // Functions - dist() { return Math.sqrt(this.x * this.x + this.y * this.y); } + dist(): number { return Math.sqrt(this.x * this.x + this.y * this.y); } // Static members static origin = new Point(0, 0); @@ -137,9 +137,9 @@ class Point3D extends Point { } // Overwrite - dist() { + dist(): number { let d = super.dist(); - return Math.sqrt(d() * d() + this.z * this.z); + return Math.sqrt(d * d + this.z * this.z); } } -- cgit v1.2.3